2013-12-13 52 views
2

我开始使用一个polyglot java/scala项目上的Gradle。 Java模块是使用JDK 1.6构建的旧模块,因此我决定让我的构建环境使用较早的JDK。具有混合Java/Scala项目和SDK 1.6的Gradle和IntelliJ

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

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(我们的代码看起来像那样)。

现在我创建了一个全新的摇篮项目(不依赖/构建工具被使用过)有两个模块:

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成功了。

+0

您在IntelliJ中设置了哪个JDK? –

+0

@PeterNiederwieser JDK 1.6,这是目前安装的唯一一个。不过,在此之前我已经安装了JDK 1.7。 –

+0

听起来就像您使用外部Scala编译器,它也联合编译Java代码并使用JDK 1.7。 –

回答

0

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