Why does my consumer prefer java 8 variant to java 11 variant while building with Java 11?

Hi @johnybravo ,

There is a method, mapToMavenScope that may be called to add outgoing variants to a maven scope.

Something like this should do the trick (untested):

AdhocComponentWithVariants javaComponent = (AdhocComponentWithVariants) project.components.findByName("java")
javaComponent.withVariantsFromConfiguration(configurations.java11ApiElements) {
	it.mapToMavenScope('runtime') // or compile if you want these to leak to the consumer compile classpath
}
javaComponent.withVariantsFromConfiguration(configurations.java11RuntimeElements) {
	it.mapToMavenScope('runtime')
}

As far as I am concerned, I am fine with the default behavior. I just need to tweak the pom generated by the maven-publish plugin to add java11 only dependencies in a Maven profile activated by jdk >= 11.

That’s quite close to plumbing, but should be doable with few adjustments.

1 Like