无法使用Gradle和Kotlin编译项目

时间:2017-10-23 07:38:54

标签: gradle kotlin

在将kotlin-gradle-plugin从1.1.4-3升级到1.1.50(或51)以及所有与Kotlin相关的库后,我在尝试导入gradle文件时遇到如下错误:

Unable to build Kotlin project configuration
Details: java.lang.reflect.InvocationTargetException: null
Caused by: java.lang.NoSuchMethodError: kotlin.reflect.jvm.internal.KClassImpl.getData()Lkotlin/reflect/jvm/internal/ReflectProperties$LazyVal;

使用旧版插件(1.1.4-3)时编译工作正常。

完整的gradle文件:

apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
apply plugin: "net.ltgt.apt"
apply plugin: 'idea'
apply plugin: 'org.jetbrains.dokka'




def daggerVersion = "2.11"

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.9"
        classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.2'
        classpath "net.ltgt.gradle:gradle-apt-plugin:0.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    }
}

dependencies {
    compile "com.google.appengine:appengine-api-1.0-sdk:${appengineVersion}"
    compile "com.google.appengine:appengine-endpoints-deps:${appengineVersion}"

    compile "com.google.dagger:dagger:${daggerVersion}"

    compile 'com.google.endpoints:endpoints-framework:2.0.5'
    compile project(':backend')

    kapt "com.google.dagger:dagger-compiler:${daggerVersion}"
    apt "com.google.dagger:dagger-compiler:${daggerVersion}"

    testCompile 'junit:junit:4.12'

    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

    compile "com.google.code.gson:gson:2.8.2"

    compile 'org.thymeleaf:thymeleaf:3.0.7.RELEASE'

    compile 'com.warrenstrange:googleauth:1.1.2'
    compile 'org.mindrot:jbcrypt:0.4'

    testCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

    testCompile "org.mockito:mockito-core:2.+"

    testCompile "com.google.appengine:appengine-api-labs:${appengineVersion}"
    testCompile "com.google.appengine:appengine-api-stubs:${appengineVersion}"
    testCompile "com.google.appengine:appengine-tools-sdk:${appengineVersion}"
    testCompile "com.google.appengine:appengine-testing:${appengineVersion}"
}
appengine {
    stage {
        enableJarClasses = true
    }
}
repositories {
    mavenCentral()
}

compileKotlin{
    kotlinOptions{
        jvmTarget = 1.8
    }
}

dokka {
    outputFormat = 'html'
    outputDirectory = file("${buildDir}/javadoc")
}

sourceSets {
    main.java.srcDirs += 'src/main/java'
    main.java.srcDirs += 'build/generated/source/kapt/main'
    main.kotlin.srcDirs += 'src/main/kotlin'
}

idea {
    module {
        sourceDirs += file("./build/generated/source/kapt/main")
        excludeDirs -= file("$buildDir")
        excludeDirs += file("$buildDir/dependency-cache")
        excludeDirs += file("$buildDir/libs")
        excludeDirs += file("$buildDir/tmp")
    }
}

编辑 - 解决方案

只是要详细说明杰克的回答: 我必须找到gradle-wrapper.properties并将分发URL更改为:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip

1 个答案:

答案 0 :(得分:6)

我遇到了同样的问题。 使用gradle 3.4(+)将为我解决。