I am getting started with Gradle on a polyglot java/scala project. The java modules are legacy modules built using JDK 1.6 so I decided to have my build environment use the older JDK.
This has a very practical rationale. Code such as the following:
class X{
private int i;
<T extends X> void aMethod(T t){
int it = t.i;
}
}
will compile fine using JDK 1.6 but will break with JDK 1.7 with the following error:
error: i has private access in X
For this reason (although unhappily) I decided to stick to JDK 1.6 (we do have code that looks like that).
Now I created a brand new Gradle project (no dependency/build tool was used before) with two modules:
myApp
|---- common (java module)
|---- someService (depends on common)
| |---- service (scala module)
| |---- api (java client)
and set the java source and target compatibility to 1.6. If I build with gradle everything works fine, i.e., the build runs and the jars get build correctly (both java and scala), without any error.
Now I generated my IntelliJ project files using the 'idea' plugin. IntelliJ loads up the project correctly. Now when I try and build from IntelliJ (Ctrl + F9) I get the following:
Information: Modules "myApp", "someService", "common" were fully rebuilt due to project configuration/dependencies changes
Information: Compilation completed with 4 errors and 44 warnings in 2 sec
Information: 4 errors
Information: 44 warnings
Error: scala: warning: [options] bootstrap class path not set in conjunction with -source 1.6
Error: scala: 1 error
Error: scala: 43 warnings
Warning: scala: Some input files use unchecked or unsafe operations.
Warning: scala: Recompile with -Xlint:unchecked for details.
... (the warnings follow)
error: properties has private access in X
As you can see, I am now getting the JDK 1.7 error (although I'm compiling with 1.6) and the build fails. IntelliJ says there are 4 errors but I believe the root cause is just that one.
Now If I go and fix the code above as follows:
class X{
private int i;
<T extends X> void aMethod(T t){
// SDK 1.7: explicit downcast grants access to base private members
int it = ((X)t).i;
}
}
I get the following error:
scala: Error: org.jetbrains.jps.incremental.scala.remote.ServerException
java.lang.InternalError
at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:838)
...
at java.lang.ClassLoader.getBootstrapResource(ClassLoader.java:1305)
...
at sbt.classfile.Analyze$$anonfun$apply$8$$anonfun$sbt$classfile$Analyze$$anonfun$$processDependency$1$1.apply$mcV$sp(Analyze.scala:49)
...
at scala.collection.immutable.HashSet$HashSet1.foreach(HashSet.scala:153)
...
at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:44)
at org.jetbrains.jps.incremental.scala.local.CompilerImpl.compile(CompilerImpl.scala:63)
...
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
at java.lang.reflect.Method.invoke(Method.java:606)
at com.martiansoftware.nailgun.NGSession.run(Unknown Source)
Caused by: java.io.FileNotFoundException: /usr/lib/jvm/java-7-oracle/jre/lib/resources.jar
...
which I believe is caused by the fact that I uninstalled JDK 1.7 and installed JDK 1.6 and somewhere in the IntelliJ paths something is still pointing at the old JDK.
So I have two questions: 1. How to get rid of any reference to JDK 1.7 in IntelliJ? 2. How to get rid of the first error altogether without changing the code? I know this is possible because Gradle does it successfully.
Silly me! I had uninstalled JDK 7 without restarting IntelliJ so it was still pointing to some of the JDK 7 folders. This was a very odd experience!