Composite build fails because of jvm versions - how to fix?

Hi there. I’m trying to make a composite build work, but I’m getting errors regarding JVM version requirements.

The composite build is putting together 4 projects. Each of them works as expected independently. All work together when driven with a shell script and with modified gradle dependencies so they use each others’ products. I am only trying the composite build route to ease the dependency changes in each project during development. But apparently the composite build is creating some additional JVM versioning requirements.

The error I’m getting says that one of the substituted dependencies fails because the required JVM version doesn’t match:

Could not determine the dependencies of task ‘:sidechains-web3j-gradle-plugin:compileTestJava’.

Could not resolve all task dependencies for configuration ‘:sidechains-web3j-gradle-plugin:testCompileClasspath’.
Could not resolve org.web3j:core:4.6.0-SNAPSHOT.
Required by:
project :sidechains-web3j-gradle-plugin
Unable to find a matching variant of project :sidechains-web3j:core:
- Variant ‘apiElements’ capability org.web3j:core:4.6.0-SNAPSHOT:
- Incompatible attribute:
- Required org.gradle.jvm.version ‘8’ and found incompatible value ‘11’.
- Other attributes:
- Found org.gradle.category ‘library’ but wasn’t required.
- Required org.gradle.dependency.bundling ‘external’ and found compatible value ‘external’.
- Required org.gradle.libraryelements ‘classes’ and found compatible value ‘jar’.
- Required org.gradle.usage ‘java-api’ and found compatible value ‘java-api’.

The version 8 requirement seems to come from sidechains-web3j-gradle-plugin, which does sourceCompatibility = 1.8.

My questions are:

  • Both mentioned projects in that error message do use sourceCompatibility=targetCompatibility=1.8. This must be the source of the required v8. Where did the incompatible 11 come from? Is it because the composite build is being run on a v11 JVM?
  • If so, is there anything I can do to fix this, given that other included builds do need a v11 JVM?
  • Is it correct that sourceCompatibility translates into a JVM requirement?
  • More generally: are composite builds supposed to work even if each project uses different Gradle and JVM versions? Project sidechains-web3j-gradle-plugin uses Gradle 5.6.3. Project sidechains-web3j uses Gradle 4.10.2. As said, both use sourceCompatibility=targetCompatibility=1.8. Other included builds use different Gradle and JVM versions, going up to v11. The composite build uses Gradle 6.0.1 and just defines the included builds and calls a task in each included build. Does this all even matter?

The repositories are all open source, so if helpful I can share more of them.

I have added to both projects’ the following line in case it helped, but doesn’t seem to:

… and I also tried adding to each project’s build.gradle this:

compileJava.options.fork = true
compileJava.options.forkOptions.executable = “/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/bin/javac”
But still fails in the same way.

I made these additions because both projects need to be compiled with a JDK8, and I thought that Gradle was maybe using the composite’s JDK11 to compile, which would trigger problems. And indeed I can confirm that running the composite with JDK8 fixes that particular error.

But as stated before other included builds will need JDK11. So the question remains: can I mix Java versions in a composite build?

just cause it might save someone the few hours I wasted…
IntelliJ -> Preferences -> Build, Execution, Deployment -> Build tools -> Maven -> Gradle

and set Gradle JVM to 1.8
make sure you also have JDK 8 installed…