# Multi project with different source & target compatibility

**URL:** <https://discuss.gradle.org/t/multi-project-with-different-source-target-compatibility/14401>\
**Category:** Help/Discuss\
**Created:** [February 10, 2016, 6:43pm UTC](https://discuss.gradle.org/t/multi-project-with-different-source-target-compatibility/14401 "2016-02-10T18:43:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mastermind1981](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@mastermind1981](https://discuss.gradle.org/u/mastermind1981)\
**Post date:** [February 10, 2016, 6:43pm UTC](https://discuss.gradle.org/t/multi-project-with-different-source-target-compatibility/14401/1 "2016-02-10T18:43:31Z")

</div>

I have a multi-project gradle configuration which is using java 8 for building. I am downgrading one of the sub-project to Java 6. My problem is that while specifying `sourcecompatibility` and `targetcompatibility` to 1.6 for this project the project is building fine although he is using some Apis from Java 8 (it must not compile because I want a to compile it for java 1.6).

I have created an example of multi-module gradle project with one of the sub-project using Java 6 and another one java 8. I have used org.gradle.java.home attribute in gradle.properties for each of the sub-projects to set the Java home for each of them. Here is the [github repo](https://github.com/mastermind1981/multiModuleGradle).

The subprojects contain each one class using Apis from Java 8, the subproject using java 6 is expected to fail, but the build runs successfully.

Here is the parent `build.gradle` file :

```
group 'com.test'
version '1.0-SNAPSHOT'
repositories {
   mavenCentral()
}

```

The content of the parent `settings.gradle`:

```
rootProject.name = 'Parent'
include 'child2Java6'
include 'child1Java8'

```

the content of `build.gradle` of the Java 6 subproject :

```
group 'com.test'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
repositories {
    mavenCentral()
}
compileJava.doFirst {
    println "source compatibility " + sourceCompatibility
    println "target compatibility " + targetCompatibility
}
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

```

the content of `gradle.properties` of the Java 6 subproject :

`org.gradle.java.home=/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/`  
`build.gradle` for java 8 sub-project:

```
group 'com.test'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
    mavenCentral()
}
compileJava.doFirst {
    println "source compatibility " + sourceCompatibility
    println "target compatibility " + targetCompatibility
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

```

It’s `gradle.properties` :

`org.gradle.java.home=/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/`  
I am printing the sourceCompatibility and targetCompatibility and they have the good values for each project.

I am using `gradle clean build` for building.

The`gradle -v` outputs this :

```
------------------------------------------------------------
Gradle 2.9
------------------------------------------------------------

Build time: 2015-11-17 07:02:17 UTC
Build number: none
Revision: b463d7980c40d44c4657dc80025275b84a29e31f

   Groovy: 2.4.4
   Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
   JVM: 1.8.0_65 (Oracle Corporation 25.65-b01)
   OS: Mac OS X 10.11.1 x86_64

```

I am using Java 8 as my default Jdk.

Thanks in advance,

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [February 10, 2016, 9:38pm UTC](https://discuss.gradle.org/t/multi-project-with-different-source-target-compatibility/14401/2 "2016-02-10T21:38:29Z")

</div>

You cannot change the java.home on a per-project level, because it applies to the whole multi-project build.

Setting the source level of the compiler only has an effect on which _language features_ you can use (e.g. Lambdas). It has no effect on APIs. That is unrelated to Gradle and true even if you run javac directly. To make sure you are not using the wrong APIs, you’ll have to set the `bootClasspath` of the compile task.

```gradle
tasks.withType(JavaCompile) {
  options.fork = true
  options.bootClasspath = "path/to/rt.jar"
}

```

---

<div class="post-metadata">

**Author:** ![mastermind1981](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@mastermind1981](https://discuss.gradle.org/u/mastermind1981)\
**Post date:** [February 10, 2016, 9:52pm UTC](https://discuss.gradle.org/t/multi-project-with-different-source-target-compatibility/14401/3 "2016-02-10T21:52:33Z")

</div>

Exactly what I need thanks @st_oehme it worked perfectly
