This message was deleted.
# dependency-management
s
This message was deleted.
m
both your rules have a typo:
this.capability.group == "org.codehaus.groovy" || this.capability.group == "org.codehaus.groovy"
second test should be
org.apache.groovy
d
thanks I was trying multiple options, but it did not work even with correct checks
v
The version alignment just cares for the single modules having the same version. You need to add the capability like you mentioned, then it should initially fail without the
resolutionStrategy
due to same capability. Then the
resolutionStrategy
should resolve that conflict and you only need to check for the
org.apache.group
capability that should then be on both variants in your
resolutionStrategy
.
d
unfortunately that does not seem to work it fails with:
Copy code
> Could not resolve all files for configuration ':lib:testCompileClasspath'.
   > Could not find org.codehaus.groovy:groovy:.
     Required by:
         project :lib > org.gebish:geb-core:6.0
         project :lib > org.gebish:geb-core:6.0 > org.gebish:geb-ast:6.0
         project :lib > org.gebish:geb-core:6.0 > org.gebish:geb-waiting:6.0
         project :lib > org.gebish:geb-core:6.0 > org.gebish:geb-waiting:6.0 > org.gebish:geb-implicit-assertions:6.0
         project :lib > org.gebish:geb-core:6.0 > org.gebish:geb-waiting:6.0 > org.gebish:geb-exceptions:6.0
   > Could not find org.codehaus.groovy:groovy-templates:.
     Required by:
         project :lib > org.gebish:geb-core:6.0
         project :lib > org.gebish:geb-core:6.0 > org.gebish:geb-ast:6.0
         project :lib > org.gebish:geb-core:6.0 > org.gebish:geb-waiting:6.0
         project :lib > org.gebish:geb-core:6.0 > org.gebish:geb-waiting:6.0 > org.gebish:geb-implicit-assertions:6.0
         project :lib > org.gebish:geb-core:6.0 > org.gebish:geb-waiting:6.0 > org.gebish:geb-exceptions:6.0
   > Could not find org.codehaus.groovy:groovy-macro:.
     Required by:
         project :lib > org.gebish:geb-core:6.0 > org.gebish:geb-ast:6.0
my configuration:
Copy code
configurations.configureEach {
    resolutionStrategy {
        capabilitiesResolution.all {
            if (this.capability.group == "org.apache.groovy") {
                this.selectHighestVersion()
            }
        }
    }
}
dependencies {
    components.all(GroovyVersionAlign::class.java)
    testImplementation("org.apache.groovy:groovy-all:4.0.6")
    testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
    testImplementation("org.gebish:geb-core:6.0")
}
class GroovyVersionAlign : ComponentMetadataRule {
    override fun execute(context: ComponentMetadataContext) = context.details.run {
        if (id.group.equals("org.codehaus.groovy")) {
            allVariants {
                withCapabilities {
                    addCapability("org.apache.groovy", id.name, id.version)
                }
            }
        }
    }
}
Also maybe I oversimplified the question, I need align version of all groovy libraries to same version so if in some project I have only plain groovy library and in some transitive dependency there is groovy-xml I need also groovy-xml to be on the same version. On the simple project I was simply able to make it work by depending on groovy-all without any custom ComponentMetadataRules since new groovy libraries have also capability with codehaus group and thus conflicting during resolution. But if I have only groovy in that module then it failed since there is groovy 4.0.6 and groovy-macro 3.0.12 on the compile classpath
v
Ah, ok, as they set the capabilities properly for Groovy 4, then you of course do not need the
addCapability
, just the
resolutionStrategy
. And as they also define the version alignment properly in Groovy 4, you also not need the manual version alignment. If you do the version alignment you should use the non-virtual
groovy-bom
though. So if you know Groovy 4 will be present, this is enough (just tested):
Copy code
configurations.all {
    resolutionStrategy {
        capabilitiesResolution.all {
            if (capability.group == "org.codehaus.groovy") {
                selectHighestVersion()
            }
        }
    }
}
dependencies {
    testImplementation("org.apache.groovy:groovy-all:4.0.6")
    testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
    testImplementation("org.gebish:geb-core:6.0")
}
If you know for sure you only have Groovy 3, this would be enough:
Copy code
dependencies {
    components.all<GroovyVersionAlign>()
    testImplementation("org.apache.groovy:groovy-all:4.0.6")
    testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
    testImplementation("org.gebish:geb-core:6.0")
}
class GroovyVersionAlign : ComponentMetadataRule {
    override fun execute(context: ComponentMetadataContext) = context.details.run {
        if (id.group.equals("org.codehaus.groovy")) {
            belongsTo("org.codehaus.groovy:groovy-bom:${id.version}", false)
        }
    }
}
And if you might have Groovy 3 and 4 or maybe not, then this works:
Copy code
configurations.all {
    resolutionStrategy {
        capabilitiesResolution.all {
            if (capability.group == "org.codehaus.groovy") {
                selectHighestVersion()
            }
        }
    }
}
dependencies {
    components.all<GroovyVersionAlign>()
    testImplementation("org.apache.groovy:groovy-all:4.0.6")
    testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
    testImplementation("org.gebish:geb-core:6.0")
}
class GroovyVersionAlign : ComponentMetadataRule {
    override fun execute(context: ComponentMetadataContext) = context.details.run {
        if (id.group.equals("org.codehaus.groovy")) {
            belongsTo("org.codehaus.groovy:groovy-bom:${id.version}", false)
        }
    }
}
d
thank you for suggestions, unfortunately it still behaves incorrectly for me I applied the last suggestion with both 3 and 4, the compilation now works (somehow?!?) but it has still multiple versions of groovy on the classpath as can be seen by configuring compile task:
Copy code
tasks.named<GroovyCompile>("compileTestGroovy") {
    doFirst {
        println(classpath.files.filter {it.name.contains("groovy")}.joinToString("\n") { it.parentFile.parentFile.parentFile.parentFile.name + ":" + it.name })
    }
}
then if I have groovy-all:4 then the classpath is like:
Copy code
org.apache.groovy:groovy-ant-4.0.6.jar
org.apache.groovy:groovy-cli-picocli-4.0.6.jar
org.apache.groovy:groovy-console-4.0.6.jar
org.apache.groovy:groovy-datetime-4.0.6.jar
org.apache.groovy:groovy-docgenerator-4.0.6.jar
org.apache.groovy:groovy-groovydoc-4.0.6.jar
org.apache.groovy:groovy-groovysh-4.0.6.jar
org.apache.groovy:groovy-jmx-4.0.6.jar
org.apache.groovy:groovy-json-4.0.6.jar
org.apache.groovy:groovy-jsr223-4.0.6.jar
org.apache.groovy:groovy-macro-4.0.6.jar
org.apache.groovy:groovy-nio-4.0.6.jar
org.apache.groovy:groovy-servlet-4.0.6.jar
org.apache.groovy:groovy-sql-4.0.6.jar
org.apache.groovy:groovy-swing-4.0.6.jar
org.apache.groovy:groovy-templates-4.0.6.jar
org.apache.groovy:groovy-test-junit5-4.0.6.jar
org.apache.groovy:groovy-test-4.0.6.jar
org.apache.groovy:groovy-xml-4.0.6.jar
org.apache.groovy:groovy-yaml-4.0.6.jar
org.apache.groovy:groovy-4.0.6.jar
org.codehaus.groovy:groovy-3.0.12.jar
if I have only groovy:4 then:
Copy code
org.apache.groovy:groovy-4.0.6.jar
org.codehaus.groovy:groovy-macro-3.0.12.jar
org.codehaus.groovy:groovy-templates-3.0.12.jar
org.codehaus.groovy:groovy-3.0.12.jar
and just for fun if I have both groovy-all:4 and groovy:4 (compilation fails like with the original message) and classpath is like:
Copy code
org.apache.groovy:groovy-ant-4.0.6.jar
org.apache.groovy:groovy-cli-picocli-4.0.6.jar
org.apache.groovy:groovy-console-4.0.6.jar
org.apache.groovy:groovy-datetime-4.0.6.jar
org.apache.groovy:groovy-docgenerator-4.0.6.jar
org.apache.groovy:groovy-groovydoc-4.0.6.jar
org.apache.groovy:groovy-groovysh-4.0.6.jar
org.apache.groovy:groovy-jmx-4.0.6.jar
org.apache.groovy:groovy-json-4.0.6.jar
org.apache.groovy:groovy-jsr223-4.0.6.jar
org.apache.groovy:groovy-macro-4.0.6.jar
org.apache.groovy:groovy-nio-4.0.6.jar
org.apache.groovy:groovy-servlet-4.0.6.jar
org.apache.groovy:groovy-sql-4.0.6.jar
org.apache.groovy:groovy-swing-4.0.6.jar
org.apache.groovy:groovy-templates-4.0.6.jar
org.apache.groovy:groovy-test-junit5-4.0.6.jar
org.apache.groovy:groovy-test-4.0.6.jar
org.apache.groovy:groovy-xml-4.0.6.jar
org.apache.groovy:groovy-yaml-4.0.6.jar
org.apache.groovy:groovy-4.0.6.jar
org.codehaus.groovy:groovy-macro-3.0.12.jar
org.codehaus.groovy:groovy-templates-3.0.12.jar
org.codehaus.groovy:groovy-3.0.12.jar
I really don't have idea how this could happen since the capabilities seems to be set correctly but it behaves like there is conflict only for some libraries or even no conflict in the last case...
v
Hm, I have a feeling this is a bug you should report to Gradle. With
Copy code
testImplementation("org.apache.groovy:groovy-all:4.0.6")
    testImplementation("org.codehaus.groovy:groovy:3.0.12")
it works perfectly as expected, but with
Copy code
testImplementation("org.apache.groovy:groovy-all:4.0.6")
    testImplementation("org.gebish:geb-core:6.0")
it does not work properly. Unless there is some detail I don't see why it works differently there.
The
capabilitiesResolution
is only called for
org.codehaus.groovy:groovy-macro
and
org.codehaus.groovy:groovy-templates
, but not for
org.codehaus.groovy:groovy
.
d
Ok I will create bug. Thank you for your help with this.
v
Don't forget to post the link here :-)
d
Here is the link to the issue: https://github.com/gradle/gradle/issues/22609
👌 1
v
Very good idea to use the linen link as reference 👌
👍 1