Gradle dependencymanagement

I am migrating the Maven project to Gradle. I needed to manage dependencies, so I tried resolutionStrategy as follows:

def dependencyVersions = [ 'org.slf4j:slf4j-api' : '1.7.2', 'javax.inject:javax.inject' : '1', 'com.google.code.findbugs:annotations' : '2.0.1', 'com.typesafe:config' : '1.0.0', 'ch.qos.logback:logback-classic' : '1.0.9', 'com.google.guava:guava' : '14.0', 'com.google.inject:guice' : '3.0', 'com.google.inject.extensions:guice-multibindings' : '3.0', 'com.google.code.gson:gson' : '2.2.2', 'joda-time:joda-time' : '2.1', 'com.thoughtworks.paranamer:paranamer' : '2.5.2', 'org.codehaus.groovy:groovy-all' : '2.0.6', 'commons-validator:commons-validator': '1.4.0', 'org.apache.shiro:shiro-core' : '1.2.1', 'junit:junit-dep' : '4.10', 'org.mockito:mockito-core' : '1.9.5', 'org.hamcrest:hamcrest-core': '1.3', 'org.hamcrest:hamcrest-library': '1.3', 'org.unitils:unitils-core': '3.3' ] configurations.all { resolutionStrategy { eachDependency { DependencyResolveDetails details -> def version = dependencyVersions["$details.requested.group:$details.requested.name"] if (version != null) details.useVersion version } } } 

but now when I try to install Gradle (in the local Maven repository), I get this error:

 Execution failed for task ':counter-module:install'. 

Could not publish configuration archives' Failed to initialize POM pom-default.xml: failed to check POM for lt.counter project in / home / workspace / counter / counter -module / build / poms / pom-default.xml

+6
source share
2 answers

I may still miss the aspect of your problem, but I just noticed something in the docs.

 // force certain versions of dependencies (including transitive) // *append new forced modules: force 'asm:asm-all:3.3.1', 'commons-io:commons-io:1.4' // *replace existing forced modules with new ones: forcedModules = ['asm:asm-all:3.3.1'] 

It looks like you could do the following:

 def dependencyVersions = [ 'org.slf4j:slf4j-api' : '1.7.2', 'javax.inject:javax.inject' : '1', 'com.google.code.findbugs:annotations' : '2.0.1', 'com.typesafe:config' : '1.0.0', 'ch.qos.logback:logback-classic' : '1.0.9', 'com.google.guava:guava' : '14.0', 'com.google.inject:guice' : '3.0', 'com.google.inject.extensions:guice-multibindings' : '3.0', 'com.google.code.gson:gson' : '2.2.2', 'joda-time:joda-time' : '2.1', 'com.thoughtworks.paranamer:paranamer' : '2.5.2', 'org.codehaus.groovy:groovy-all' : '2.0.6', 'commons-validator:commons-validator': '1.4.0', 'org.apache.shiro:shiro-core' : '1.2.1', 'junit:junit-dep' : '4.10', 'org.mockito:mockito-core' : '1.9.5', 'org.hamcrest:hamcrest-core': '1.3', 'org.hamcrest:hamcrest-library': '1.3', 'org.unitils:unitils-core': '3.3' ] force dependencyVersion.collect {k, v -> "$k:$v"} 

In my opinion, it seems that this will fulfill two principles.

  • Give users a beautiful map notation to use when they want to play beautifully, and add a fingerprint with your predefined version.
  • Forced to use a predefined version at any time when they are trying to get confused.
+4
source

The default resolution strategy for Gradle is to use the latest version, so version N will be used; version N-1 will not be.

You will not tell us which version of Gradle you are using and the full structure of your project (s). Do you do multi-project builds?

Also, I do not understand your user permission strategy - why would the version always be zero?

- change -

The newest version is the default resolution strategy, so the highest version will be used.

Perhaps look at Gradle for examples of user-resolution strategies , such as forcing a specific version.

0
source

Source: https://habr.com/ru/post/947651/


All Articles