2013-12-13 51 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文件夾。這是一個非常奇怪的經歷!