Spawn Java 6 jvm from Java 7


(david koch) #1

Hello, I try to run a java 6 gradle build by starting gradle with java 7 (default on my machine). Therefor I set the property “org.gradle.java.home” in the gradle.properties file to the home of my java 6 installation. Right after the gradle start I get warning from gradle that spawning jvms might be slow. In the process list I see that there are two java machines are started. But it doesn’t work well.

When printing out Java System properties I see that some properties point to my currentJdk (my current jdk 7 where also $JAVA_HOME env is pointing to) and some point to currentJdk6 (my jdk 6 installation). It pretends to be a java 7 but “java.home” is pointing to the jdk6.

Nevertheless trying to use Java 7 classes like java.nio.file.Paths fails.

Is there a way to get the build run in a full compatible jdk 6 environment even when started with jdk 7? Thanks, David

Some system properties related to this: sun.boot.library.path: C:\Program Files\Java\currentJdk\jre\bin java.vm.version: 23.3-b01 java.runtime.version: 1.7.0_07-b11 java.endorsed.dirs: C:\Program Files\Java\currentJdk\jre\lib\endorsed java.class.version: 51.0 java.specification.version: 1.7 java.vm.specification.version: 1.7 java.home: C:\Program Files\Java\currentJdk6\jre java.vm.info: mixed mode java.version: 1.7.0_07 java.ext.dirs: C:\Program Files\Java\currentJdk\jre\lib\ext;C:\windows\Sun\Java\lib\ext sun.boot.class.path: C:\Program Files\Java\currentJdk\jre\lib\resources.jar;C:\Program Files\Java\currentJdk\jre\lib\rt.jar;C:\Program Files \Java\currentJdk\jre\lib\sunrsasign.jar;C:\Program Files\Java\currentJdk\jre\lib\jsse.jar;C:\Program Files\Java\currentJdk\jre\lib\jce.jar;C :\Program Files\Java\currentJdk\jre\lib\charsets.jar;C:\Program Files\Java\currentJdk\jre\lib\jfr.jar;C:\Program Files\Java\currentJdk\jre\c lasses org.gradle.java.home: C:/Program Files/Java/currentJdk6


(sethgoings) #2

Are you just trying to compile with a different source compatibility? http://gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.JavaCompile.html


(david koch) #3

Actually yes. But it seems to be not so simple as it appears in the first place to reach smooth java 6 compatibility see config example below. To compile Java 6 is the one thing but I need also a Java 6 compatible projects for eclipse developers.

So I thought using Jdk 6 would be quite simpler. Since on most machines my team and I have to maintain Java 7 is default I wished gradle could select the right java though configuration. Otherwise I always need to call a shell scipt (*.sh, *.bat) prior to the gradle build :frowning: bye, David

if(java6Home==null && javaVersion != "1.6") {
  throw new GradleException("Java 1.6 is required")
}
compileJava {
  sourceCompatibility = 1.6
  targetCompatibility = 1.6
  options.bootClasspath = java6Home==null ? null : "${java6Home}/jre/lib/rt.jar"
}
eclipse {
  jdt {
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
    //STILL NEED TO FIND OUT HOW to set system lib config for java 1.6
  }
  wtp {
    facet {
      withXml { provider ->
        //STILL NEED TO FIND OUT HOW to change "jst.java" to java 1.6
      }
    }
  }
}

(Peter Niederwieser) #4

This may be related to GRADLE-2460, which has been fixed for 1.3. You can try out a nightly build.