kotlin项目不能用gradle构建(找不到参考)

时间:2016-06-07 10:21:28

标签: java intellij-idea gradle build kotlin

我有一个用kotlin编写的java项目,我使用intelliJ IDEA来开发这个项目。我在依赖项设置(多个项目)上遇到了麻烦。我已经阅读了很多例子,但我找不到解决方法,这里是我的依赖设置代码,它可以正确地在java类中构建,但是kotlin类会出现很多错误' Unresolved reference&# 39; 。我的设置或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')}}

0 个答案:

没有答案