使用混合Java / Scala项目和SDK 1.6的Gradle和IntelliJ

时间:2013-12-13 15:13:19

标签: java scala intellij-idea gradle jdk6

我在一个多语言java / scala项目上开始使用Gradle。 java模块是使用JDK 1.6构建的遗留模块,所以我决定让我的构建环境使用旧的JDK。

这有一个非常实用的理由。代码如下:

class X{
  private int i;
  <T extends X> void aMethod(T t){
    int it = t.i;
  }
}

将使用JDK 1.6进行编译,但会因JDK 1.7而中断,并出现以下错误:

 error: i has private access in X

出于这个原因(虽然不幸)我决定坚持使用JDK 1.6(我们的代码看起来很像)。

现在我用两个模块创建了一个全新的Gradle项目(之前没有使用过依赖/构建工具):

myApp
|---- common (java module)
|---- someService (depends on common)
|     |---- service (scala module)
|     |---- api (java client)

并将java源和目标兼容性设置为1.6。如果我使用gradle构建一切正常,即构建运行并且jar正确构建(包括java和scala),没有任何错误。

现在我使用'idea'插件生成了我的IntelliJ项目文件。 IntelliJ正确加载项目。现在,当我尝试使用IntelliJ(Ctrl + F9)构建时,我得到以下内容:

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

正如您所看到的,我现在收到JDK 1.7错误(虽然我正在编译1.6)并且构建失败。 IntelliJ说有4个错误,但我认为根本原因就是那个错误。

现在如果我按照以下方式修改上面的代码:

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;
  }
}

我收到以下错误:

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
  ...

我认为这是因为我卸载了JDK 1.7并安装了JDK 1.6并且在IntelliJ路径中的某个地方仍然指向旧的JDK。

所以我有两个问题: 1.如何摆脱IntelliJ中对JDK 1.7的任何引用? 2.如何在没有更改代码的情况下完全摆脱第一个错误?我知道这是可能的,因为Gradle成功了。

1 个答案:

答案 0 :(得分:0)

傻傻的我!我没有重新启动IntelliJ就卸载了JDK 7,所以它仍然指向一些JDK 7文件夹。这是一次非常奇怪的经历!