更新:
我在Github中放了一个演示:TestBuildSrc,在buildSrc文件夹下只有一个Kotlin文件和一个Java文件。发生相同的错误(Test是一个Java类):
Unresolved reference: Test
旧问题:
我需要一个R2文件,所以我将JakeWharton的butterknife-gradle-plugin复制到我的buildSrc目录中。
奇怪的是,当我在Kotlin文件中调用Java类时,发生了一些错误:
> Task :buildSrc:compileKotlin FAILED
w: Runtime JAR files in the classpath have the version 1.1, which is older than the API version 1.3. Consider using the runtime of version 1.3, or pass '-api-version 1.1' explicitly to restrict the available APIs to the runtime of version 1.1. You can also pass '-language-version 1.1' instead, which will restrict not only the APIs to the specified version, but also the language features
w: /Users/rainfool/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.1.3-2/2104f139db2a2d230c529b004c34a0993c4c2f19/kotlin-reflect-1.1.3-2.jar: Runtime JAR file has version 1.1 which is older than required for API version 1.3
w: /Users/rainfool/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.1.3-2/9b44c139a4ec57031e0c84ba0e49ba16df6d801c/kotlin-stdlib-1.1.3-2.jar: Runtime JAR file has version 1.1 which is older than required for API version 1.3
e: /Users/rainfool/WorkSpaceGitHuya/ViewComponent/buildSrc/src/main/kotlin/RLibPlugin.kt: (4, 47): Unresolved reference: Test
e: /Users/rainfool/WorkSpaceGitHuya/ViewComponent/buildSrc/src/main/kotlin/RLibPlugin.kt: (84, 29): Unresolved reference: Test
e: /Users/rainfool/WorkSpaceGitHuya/ViewComponent/buildSrc/src/main/kotlin/com.duowan.viewcomponent.plugin/rfinal/Drive.kt: (11, 9): Unresolved reference: Test
e: /Users/rainfool/WorkSpaceGitHuya/ViewComponent/buildSrc/src/main/kotlin/com.duowan.viewcomponent.plugin/rfinal/RLibPlugin.kt: (84, 29): Unresolved reference: FinalRClassBuilder
e: /Users/rainfool/WorkSpaceGitHuya/ViewComponent/buildSrc/src/main/kotlin/com.duowan.viewcomponent.plugin/rfinal/RLibPlugin.kt: (85, 29): Unresolved reference: Test
FAILURE: Build failed with an exception.
Test或FinalRClassBuilder是Java类。 我的gradle文件在buildSrc文件夹下(修改源集块不起作用):
apply plugin: 'kotlin'
apply plugin: "groovy"
...
sourceSets {
main {
// groovy {
// srcDir 'src/main/java'
// }
kotlin {
// srcDir 'src/main/java'
srcDir 'src/main/kotlin'
}
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/main/resources'
}
}
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
这里发生了什么?