Search code examples
gradlebuildbuild.gradlemulti-project

In multibuild project with Gradle 5.4, sourceSompatiblity with java 8 is not taking effect


I am trying to have multibuild project with different java versions for some subprojects, using Gradle 5.4 and Intellij.
First I updated all of my subprojects to have the code below in the beginning of build.gradle

apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6

After importing Gradle project in Intellij, Intellij has been updated with iml files with this line:

<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6">

Then I updated a specific subproject with java 8 instead of Java 6 as below {code} apply plugin: 'java' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 {code} but iml files didn't change. I tried with different things but it seems that gradle is ignoring Java 8. I changed Java 8 to Java 7 and the iml file was updated to:

I updated gradle file with java 9 with sourceCompatibility = JavaVersion.VERSION_1_8 and then gradle updated all projects to use java 8! even the subprojects which had source and target compatibility set to Java 1.6. Is this a bug or shall am I missing something? Something which I don't know if it is related is that when I am running compileJava then I am getting the below warning:

warning: [options] bootstrap class path not set in conjunction with -source 1.6

Solution

  • I could solve this. The problem was that the Default language level in Intellij Project was java 6. I changed it to Java 8. Then in the main project build gradle under sub projects I added

    apply plugin: 'java'
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    

    Then only for the sub projects that I want to compile them with Java 6, in the beginning of their build.gradle I added

    apply plugin: 'java'
        sourceCompatibility = JavaVersion.VERSION_1_6
        targetCompatibility = JavaVersion.VERSION_1_6
    

    Then in the project's .ipr file for every java 1.6 I got a bytecodeTargetLevel:

    <bytecodeTargetLevel>
      <module name="common" target="1.6" />
    </bytecodeTargetLevel>
    

    and in each iml file for java 1.6 language level was added to main component as below:

    <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6">