Error: Cannot choose between the following variants

Hello,

I’m trying to upgrade this project from Spring Boot 2.2.4 to 2.4.3 but now I’m running into a Gradle issue:

Script 'C:\Users\bert\workspace\yona-server\dbinit\liquibase.gradle' line: 31

* What went wrong:
Execution failed for task ':dbinit:liquibasePathingJar'.
> Could not resolve all files for configuration ':dbinit:runtime'.
   > Could not resolve project :core.
     Required by:
         project :dbinit
      > Cannot choose between the following variants of project :core:
          - productionRuntimeClasspath
          - runtimeElements
        All of them match the consumer attributes:
          - Variant 'productionRuntimeClasspath' capability yonadev:core:0.0.8-SNAPSHOT:
              - Unmatched attributes:
                  - Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'runtimeElements' capability yonadev:core:0.0.8-SNAPSHOT:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it
                  - Provides org.gradle.jvm.version '11' but the consumer didn't ask for it
                  - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it

The line 31 mentioned above is the one starting with “attributes” in the below task:

task liquibasePathingJar(type: Jar) {
	dependsOn configurations.liquibase
	appendix = 'pathing'
	doFirst {
		manifest {
			attributes "Class-Path": (configurations.runtime.files + configurations.liquibase.files).collect {
				it.toURL().toString().replaceFirst(/file:\/+/, '/')
			}.join(' ')
		}
	}
}

This occurs with Gradle 6.8.2.

My knowledge about Gradle is quite limited. I have been googling quite a bit, but I cannot find out how I can influence the variant matching to address this. Your help is highly appreciated!

Regards,
Bert

I found a fix:
If I replace configurations.runtime.files with configurations.productionRuntimeClasspath.files, it works.

Besides that the runtime configuration is deprecated since years, it is / was not meant to be used for resolving, but only for declaring dependencies. runtimeClasspath or obviously with spring boot productionRuntimeClasspath are intended for resolving and declare the attributes that are needed for variant-aware resolution, so your solution is fine.

Thank you! I’ve created a ticket to do this update throughout.