# Gradle Multi Project using both Java8 and Java11

**URL:** <https://discuss.gradle.org/t/gradle-multi-project-using-both-java8-and-java11/32679>\
**Category:** Help/Discuss\
**Created:** [August 5, 2019, 3:23pm UTC](https://discuss.gradle.org/t/gradle-multi-project-using-both-java8-and-java11/32679 "2019-08-05T15:23:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![citizenkahn](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/citizenkahn/32/7907_2.png) [@citizenkahn](https://discuss.gradle.org/u/citizenkahn)\
**Post date:** [August 5, 2019, 3:23pm UTC](https://discuss.gradle.org/t/gradle-multi-project-using-both-java8-and-java11/32679/1 "2019-08-05T15:23:56Z")

</div>

Is it possible to have a gradle multi module project that uses both java 8 and java 11? Is the proper approach to upgrade gradle to latest, build under java 11 JDK and then per project use the **sourceCompatibility** and **targetCompatibility** set to 8 for some subprojects?

---

<div class="post-metadata">

**Author:** ![Bjorn\_Vester](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bjorn_vester/32/7839_2.png) [@Bjorn\_Vester](https://discuss.gradle.org/u/Bjorn_Vester)\
**Post date:** [August 5, 2019, 4:33pm UTC](https://discuss.gradle.org/t/gradle-multi-project-using-both-java8-and-java11/32679/2 "2019-08-05T16:33:49Z")

</div>

Yes, that will work. But you will still be compiling against the Java 11 SDK, and you could accidentally reference something that is not present in Java 8. In that case, everything will compile file, but you will get a runtime error instead. This may not be a problem, but if it is, there are a few ways around it.

You can either compile with Java 8 like this:

```gradle
compileJava {
    options.fork = true
    options.forkOptions.executable = "/path/to/jdk8/bin/javac"
    options.bootstrapClasspath = files("/path/to/jdk8/jre/lib/rt.jar")
}

```

Or you can use the `--release` flag in Java 11:

```gradle
compileJava {
  options.compilerArgs = ['--release', '8']
}

```

If you want to run your test under Java 8 as well, you will need something like this:

```gradle
test {
    executable = "/path/to/jdk8/bin/java"
}

```

---

<div class="post-metadata">

**Author:** ![citizenkahn](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/citizenkahn/32/7907_2.png) [@citizenkahn](https://discuss.gradle.org/u/citizenkahn)\
**Post date:** [August 16, 2019, 1:54pm UTC](https://discuss.gradle.org/t/gradle-multi-project-using-both-java8-and-java11/32679/3 "2019-08-16T13:54:25Z")

</div>

Thanks. Luckily the team opted for breaking up the project upgrade work by tool rather than subproject. Gradle 5 first, spring next then java.
