Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8

Hi, We’re using Springfox repo which in turn uses grgit as a plugin in its build.gradle like below.

plugins {
...
id "org.ajoberstar.grgit" version "4.0.2"
id "org.ajoberstar.git-publish" version "3.0.0-rc.1"
...
}

gradle version used is : distributionUrl=https://services.gradle.org/distributions/gradle-6.5-bin.zip
java version is : java 8 (Currently our product and server runs on java 8)

The Springfox repo used to get complied successfully before, but when we try building it again after 1 or 2 years without any changes , compilation gets failed with below error which mentions about java 8 and java 11 compatibility. Can you please help here how to get it complied successfully using java 8? Because as mentioned, we haven’t changed anything in the repo at all. Still the compilation which used to work earlier, isn’t working now with java 8.

22:59:06 * What went wrong:
22:59:06 A problem occurred configuring root project 'springfox'.
22:59:06 > Could not resolve all artifacts for configuration ':classpath'.
22:59:06 > Could not resolve org.ajoberstar.grgit:grgit-core:4.0.2.
22:59:06 Required by:
22:59:06 project : > org.ajoberstar.grgit:org.ajoberstar.grgit.gradle.plugin:4.0.2 > org.ajoberstar.grgit:grgit-gradle:4.0.2
22:59:06 > The consumer was configured to find a runtime of a component compatible with Java 8, packaged as a jar, and its dependencies declared externally. However we cannot choose between the following variants of org.ajoberstar.grgit:grgit-core:5.2.0:
22:59:06 - javadocElements
22:59:06 - sourcesElements
22:59:06 All of them match the consumer attributes:
22:59:06 - Variant 'javadocElements' capability org.ajoberstar.grgit:grgit-core:5.2.0 declares a runtime of a component, and its dependencies declared externally:
22:59:06 - Unmatched attributes:
22:59:06 - Provides documentation but the consumer didn't ask for it
22:59:06 - Provides javadocs but the consumer didn't ask for it
22:59:06 - Doesn't say anything about its target Java version (required compatibility with Java 8)
22:59:06 - Doesn't say anything about its elements (required them packaged as a jar)
22:59:06 - Provides release status but the consumer didn't ask for it
22:59:06 - Variant 'sourcesElements' capability org.ajoberstar.grgit:grgit-core:5.2.0 declares a runtime of a component, and its dependencies declared externally:
22:59:06 - Unmatched attributes:
22:59:06 - Provides documentation but the consumer didn't ask for it
22:59:06 - Provides sources but the consumer didn't ask for it
22:59:06 - Doesn't say anything about its target Java version (required compatibility with Java 8)
22:59:06 - Doesn't say anything about its elements (required them packaged as a jar)
22:59:06 - Provides release status but the consumer didn't ask for it
22:59:06 The following variants were also considered but didn't match the requested attributes:
22:59:06 - Variant 'apiElements' capability org.ajoberstar.grgit:grgit-core:5.2.0 declares a component, packaged as a jar, and its dependencies declared externally:
22:59:06 - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
22:59:06 - Variant 'runtimeElements' capability org.ajoberstar.grgit:grgit-core:5.2.0 declares a runtime of a component, packaged as a jar, and its dependencies declared externally:
22:59:06 - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
22:59:06 > Could not resolve org.ajoberstar.grgit:grgit-core:latest.release.
22:59:06 Required by:
22:59:06 project : > org.ajoberstar.git-publish:org.ajoberstar.git-publish.gradle.plugin:3.0.0-rc.1 > org.ajoberstar:gradle-git-publish:3.0.0-rc.1
22:59:06 > The consumer was configured to find a runtime of a component compatible with Java 8, packaged as a jar, and its dependencies declared externally. However we cannot choose between the following variants of org.ajoberstar.grgit:grgit-core:5.2.0:
22:59:06 - javadocElements
22:59:06 - sourcesElements
22:59:06 All of them match the consumer attributes:
22:59:06 - Variant 'javadocElements' capability org.ajoberstar.grgit:grgit-core:5.2.0 declares a runtime of a component, and its dependencies declared externally:
22:59:06 - Unmatched attributes:
22:59:06 - Provides documentation but the consumer didn't ask for it
22:59:06 - Provides javadocs but the consumer didn't ask for it
22:59:06 - Doesn't say anything about its target Java version (required compatibility with Java 8)
22:59:06 - Doesn't say anything about its elements (required them packaged as a jar)
22:59:06 - Provides release status but the consumer didn't ask for it
22:59:06 - Variant 'sourcesElements' capability org.ajoberstar.grgit:grgit-core:5.2.0 declares a runtime of a component, and its dependencies declared externally:
22:59:06 - Unmatched attributes:
22:59:06 - Provides documentation but the consumer didn't ask for it
22:59:06 - Provides sources but the consumer didn't ask for it
22:59:06 - Doesn't say anything about its target Java version (required compatibility with Java 8)
22:59:06 - Doesn't say anything about its elements (required them packaged as a jar)
22:59:06 - Provides release status but the consumer didn't ask for it
22:59:06 The following variants were also considered but didn't match the requested attributes:
22:59:06 - Variant 'apiElements' capability org.ajoberstar.grgit:grgit-core:5.2.0 declares a component, packaged as a jar, and its dependencies declared externally:
22:59:06 - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
22:59:06 - Variant 'runtimeElements' capability org.ajoberstar.grgit:grgit-core:5.2.0 declares a runtime of a component, packaged as a jar, and its dependencies declared externally:
22:59:06 - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8

As you can see in https://plugins.gradle.org/m2/org/ajoberstar/gradle-git-publish/3.0.0-rc.1/gradle-git-publish-3.0.0-rc.1.pom, the org.ajoberstar.git-publish plugin depens on org.ajoberstar.grgit:grgit-core:latest.release which is a really bad idea.
Due to that it tries to use 5.2.0 which is the current latest release but only works if you run Gradle with Java 11.
In 3.0.1 this was fixed to depend on 4.1.1 of grgit-core directly which is still Java 8 compatible: https://repo1.maven.org/maven2/org/ajoberstar/git-publish/gradle-git-publish/3.0.1/gradle-git-publish-3.0.1.module

So update that plugin to 3.0.1 and it should probably work again.

Btw. I strongly recommend to use JVM toolchains feature.
With that you decouple the Java version you run Gradle with from the Gradle version that is used to build or run your production code: Toolchains for JVM projects

1 Like

Thanks @Vampire , Upgrading to 3.0.1 worked. Sure will try JVM toolchains feature as well.

1 Like