Milestone 8: gradle-build using jdk 1.7 does not see javax.crypt.Cipher

With a very (!) simple build script, and a very (!) simple java file, milestone 8 will not find/see javax.crypt.Cipher when running under jdk 1.7. It works with milestone 8 and jdk 1.6, and it works with milestone 7 and jdk 1.7:

[crypt]$ cat build.gradle
 apply plugin: 'java'
[crypt]$ cat src/main/java/
 import javax.crypto.Cipher;
  class Test {
[crypt]$ JAVA_HOME=/usr/java/jdk1.6.0_25 /opt/gradle-1.0-milestone-8/bin/gradle clean compileJava
  Total time: 3.342 secs
[crypt]$ JAVA_HOME=/usr/java/jdk1.7.0_03/ /opt/gradle-1.0-milestone-7/bin/gradle clean compileJava
[ant:javac] warning: [options] bootstrap class path not set in conjunction with -source 1.5
[ant:javac] 1 warning
  Total time: 4.121 secs
[crypt]$ JAVA_HOME=/usr/java/jdk1.7.0_03/ /opt/gradle-1.0-milestone-8/bin/gradle clean compileJava
[ant:javac] /tmp/crypt/src/main/java/ error: package javax.crypto does not exist
[ant:javac] import javax.crypto.Cipher;
[ant:javac] 1 error
  FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':compileJava'.
> Compile failed; see the compiler error output for details.
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  Total time: 3.483 secs

Any ideas on why this fails, and how to fix it?

So it seems that the problem has to do with the sourceCompatibility-setting. When set to “1.5” (the default), a build on jdk 1.7 does not work properly. The workaround that I found is to force the sourceCompatibility to the level of the jdk you’re building on

// This is a "work-around"['java.specification.version']

Defaulting the source compatibility to the Java compiler version being used is already in the works, and will be available in milestone 9.

That’s nice :slight_smile:

I’m wondering, though, why the build started failing from milestone 8. As i understand it, sourceCompatibility has defaulted to 1.5 for a long time, and the build (running under 1.7) worked nicely with milestone 7. Only with milestone 8 were javax.crypto.Cipher (and probably most other jce classes) no longer available.

-> Is this a bug with milestone 8, or is it intended behaviour?

I’d prefer to be able to have sourceCompatibility set to 1.5 (or 1.6), but still be able to build it on a computer with only 1.7 installed.

Milestone 8 tried to work around a JDK 7 compiler warning by setting the compiler’s boot class path. Apparently this causes a problem in your case. This has since been reverted in favor of a better default for source and target compatibility.

Great, and thanks for your time!

I’m using a 1.7 JDK in our CI environment, but I need to compile to a target of 1.6. I am setting the compileJava target and source compatibility to 1.6, but when I do so, I get the following error:

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

I am running on gradle 1.0-RC3. When I set the bootClasspath to a 1.6 rt.jar, I get the crypto error. Is this not fixed in milestone 9 or later? Should I downgrade my gradle to work around the issue?

That’s a warning, not an error. How exactly do you set the bootstrap class path? Are you aware that this is about the compiler’s bootstrap class path, not the one for the Gradle JVM?

What the warning is telling you is that it’s not recommended to set a lower compiler source/target version and at the same time compile against a higher version of the Java class library, mainly because this won’t detect usages of methods and classes that are only available in the higher version (and hence might not be available at runtime).