I have multi-project gradle configuration which is using java 7 for building. I am adding a new project that have to be built with Java 6.
From this Q&A I have tried the different solutions proposed but none of them worked.
Here is the top level build.gradle:
allprojects {
apply plugin: 'idea'
apply plugin: 'java'
repositories {
maven { url 'http://repo1.maven.org/maven2' }
mavenLocal()
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:-options"
}
}
}
I have tried to enfore source compatibility in the child project but it seems that this has no effect.
Update:
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.
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,