kotlin项目不能在gradle中建立(找不到参考)
我有一个java项目写在kotlin,我使用intelliJ IDEA来开发这个项目。 我有依赖关系设置(多个项目)的麻烦。 我已经阅读了大量的例子,但是我找不到解决方法,这里是我的依赖设置代码,它可以正确的在java类中构建,但是kotlin类会得到很多错误'Unresolved reference'。 对于我的设置是否有任何错误或gradle是不适合与kotlin。
PS:当我只构建核心项目时,构建过程会成功,但是在测试项目中构建会得到参考未解决的错误
以下是build.gradle的代码。
allprojects { apply plugin: 'java' apply plugin: 'kotlin' group 'TestProject' version '1.0'} subprojects{ apply plugin: 'java' apply plugin: 'kotlin' def defaultEncoding = 'UTF-8' compileJava.options.encoding = defaultEncoding sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() mavenLocal()} dependencies { // Kotlin compile "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" testCompile group: 'junit', name: 'junit', version: '4.11' // JDOM compile "org.jdom:jdom:$jdom_version" // Jaxen compile group: 'jaxen', name: 'jaxen', version: '1.1.6' // JUnit compile "junit:junit:$junit_version" // Log4j2 compile "org.apache.logging.log4j:log4j-api:2.5" compile "org.apache.logging.log4j:log4j-core:2.5" // JOGL String[] versions = "$jogl_version".split("\\.") if (Integer.parseInt(versions[0]) >= 2 && Integer.parseInt(versions[1]) >= 2) { compile "org.jogamp.gluegen:gluegen-rt:$jogl_version" compile "org.jogamp.jogl:jogl-all:$jogl_version" println "JOGL 2.2.0 later" } else { compile files("../libs/thirdparty/jogl/jogl-2/jar/jogl-all.jar") compile files("../libs/thirdparty/jogl/jogl-2/jar/gluegen-rt.jar") println "JOGL 2.1.5 before"} runtime "org.jogamp.gluegen:gluegen-rt:$jogl_version:natives-linux-amd64" runtime "org.jogamp.gluegen:gluegen-rt:$jogl_version:natives-linux-i586" runtime "org.jogamp.gluegen:gluegen-rt:$jogl_version:natives-macosx-universal" runtime "org.jogamp.gluegen:gluegen-rt:$jogl_version:natives-windows-amd64" runtime "org.jogamp.gluegen:gluegen-rt:$jogl_version:natives-windows-i586" runtime "org.jogamp.jogl:jogl-all:$jogl_version:natives-linux-amd64" runtime "org.jogamp.jogl:jogl-all:$jogl_version:natives-linux-i586" runtime "org.jogamp.jogl:jogl-all:$jogl_version:natives-macosx-universal" runtime "org.jogamp.jogl:jogl-all:$jogl_version:natives-windows-amd64" runtime "org.jogamp.jogl:jogl-all:$jogl_version:natives-windows-i586" testCompile "junit:junit:$junit_version" testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" // Jython compile 'org.python:jython-standalone:2.7.0' // RxKotlin compile 'io.reactivex:rxkotlin:0.55.0' compile 'io.reactivex:rxswing:0.24.0' // Mockito compile 'org.mockito:mockito-all:1.9.5' compile 'args4j:args4j:2.33' compile 'org.json:json:20160212' // Lombok compile "org.projectlombok:lombok:$lombok_version"} sourceSets.main.java.srcDirs = ['src'] sourceSets.main.kotlin.srcDirs = ['src'] sourceSets.main.resources.srcDirs = ['../res','src'] sourceSets.test.java.srcDirs = ['test'] sourceSets.test.kotlin.srcDirs = ['test'] sourceSets.test.resources.srcDirs = ['../res','src'] buildDir = 'build'} buildscript { // JOGL ext.jogl_version = '2.1.0' // Kotlin ext.kotlin_version = '1.0.1' // JUnit ext.junit_version = '4.12' // JDOM ext.jdom_version = '1.1' // Lombok ext.lombok_version ='1.16.8' repositories { flatDir { dirs "lib" } mavenLocal() mavenCentral()} dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"}} dependencies { buildDir = 'out'} sourceCompatibility = 1.8 project(':mainproject') { dependencies { compile project(':core') compile project(':movie')}} project(':movie'){ dependencies{ compile project(':core')}}