Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle change classifier during dependency resolution

I have a dependency to a special version of a jar identified by a classifier (e.g. clover). I can easily specify it as a dependency. Unfortunately all its dependencies specified in the pom are without classifier.

compile(group: 'ch.mypackage', name: 'projectWithTransitiveDeps', version: "1.0.0-SNAPSHOT", classifier: 'clover')

I would like to change the transitive dependencies to use a classifier as well, but there's setter on the object:

configurations {
    compile.resolutionStrategy {
        eachDependency { DependencyResolveDetails details ->
            if (details.requested.group == 'ch.mypackage') {
                details.useTarget group: details.requested.group, name: details.requested.name, version: details.requested.version, classifier: 'clover'
            }
        }
    }
}

The above code will fail with an exception because classifier is an unknown property.

Is there another way to achieve this?

like image 861
Daniel Avatar asked Jan 16 '26 22:01

Daniel


1 Answers

According to the comment in gradle/gradle#8561:

There is no interest in Gradle to leak the classifier concept to constraints, as constraints effectively apply to a module while the classifier is more of an artifact concept.

it is not possible.

But you can still exclude transitive dependencies and add your own, something like this:

ext.myPackageVersion = '1.0.0-SNAPSHOT'
ext.myPackageClassifier = 'clover'

dependencies {
  compile(group: 'ch.mypackage', name: 'projectWithTransitiveDeps', version: myPackageVersion, classifier: myPackageClassifier) {
    exclude group: "ch.mypackage", module:'transitiveDep'
  }
  compile(group: 'ch.mypackage', name: 'transitiveDep', version: myPackageVersion, classifier: myPackageClassifier)
}

See also Gradle changing dependencies by classifier. There was the same underlying problem

like image 185
Basil Peace Avatar answered Jan 19 '26 13:01

Basil Peace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!