title: Gradle and IntelliJ with mixed Java/Scala project and SDK 1.6
body: <p>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.</p>
  
  <p>This has a very practical rationale. Code such as the following:</p>
  
  <pre><code>class X{
    private int i;
    &lt;T extends X&gt; void aMethod(T t){
      int it = t.i;
    }
  }
  </code></pre>
  
  <p>will compile fine using JDK 1.6 but will break with JDK 1.7 with the following error:</p>
  
  <pre><code> error: i has private access in X
  </code></pre>
  
  <p>For this reason (although unhappily) I decided to stick to JDK 1.6 (we do have code that looks like that).</p>
  
  <p>Now I created a brand new Gradle project (no dependency/build tool was used before) with two modules:</p>
  
  <pre><code>myApp
  |---- common (java module)
  |---- someService (depends on common)
  |     |---- service (scala module)
  |     |---- api (java client)
  </code></pre>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>Now If I go and fix the code above as follows:</p>
  
  <pre><code>class X{
    private int i;
    &lt;T extends X&gt; void aMethod(T t){
      // SDK 1.7: explicit downcast grants access to base private members
      int it = ((X)t).i;
    }
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>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
    ...
  </code></pre>
  
  <p>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.</p>
  
  <p>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 <em>without</em> changing the code? I know this is possible because Gradle does it successfully.</p>