Target both Java 8 and Java 9 in a single project

I currently have this project: https://github.com/Proximyst/fieldmod

It uses an older version of Gradle which supports depending on a subproject (implementation) which targets Java 9 while the root project targets Java 8. If I update this, it doesn’t work anymore (which is sane, but I want to override this).

Error faced:

Could not determine the dependencies of task ':shadowJar'.
> Could not resolve all dependencies for configuration ':runtimeClasspath'.
   > Could not resolve project :java-9-impl.
     Required by:
         project :
      > Unable to find a matching variant of project :java-9-impl:
          - Variant 'apiElements' capability fieldmod:java-9-impl:unspecified:
              - Incompatible attributes:
                  - Required org.gradle.jvm.version '8' and found incompatible value '9'.
                  - Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
              - Other attributes:
                  - Required org.gradle.category 'library' and found compatible value 'library'.
                  - Required org.gradle.dependency.bundling 'external' and found compatible value 'external'.
                  - Required org.gradle.libraryelements 'jar' and found compatible value 'jar'.
          - Variant 'runtimeElements' capability fieldmod:java-9-impl:unspecified:
              - Incompatible attribute:
                  - Required org.gradle.jvm.version '8' and found incompatible value '9'.
              - Other attributes:
                  - Required org.gradle.category 'library' and found compatible value 'library'.
                  - Required org.gradle.dependency.bundling 'external' and found compatible value 'external'.
                  - Required org.gradle.libraryelements 'jar' and found compatible value 'jar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.

How would I go around this very sane, but hindering regardless restriction?

This is a consequence of a change introduced in Gradle 5.3. You can read and learn about the way to disable it in this entry of the version upgrade guide.

1 Like