-1

Gradle 在尝试执行 grgit 任务时抛出 NoClassDefFoundError。

开始build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'org.ajoberstar:gradle-git:1.2.0'
    }
}

apply plugin: 'com.android.application'
//
//

import org.ajoberstar.grgit.*

task clone << {
    File dir = new File('contrib/otherstuff')
    if(!dir.exists()) {
        def grgit = Grgit.clone(dir: dir, uri: 'https://github.com/someguy/otherstuff.git')
    }
    // TODO else (pull)
}


project.afterEvaluate {
    preBuild.dependsOn clone
}

// rest omitted

输出:

Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:src:myproject:clone FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/home/me/src/myproject/build.gradle' line: 20

* What went wrong:
Execution failed for task ':src:myproject:clone'.
> java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/typehandling/ShortTypeHandling

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 16.937 secs

第 20 行是对 的调用Grgit.clone()

我是否需要添加 groovy 作为构建依赖项(错误消息似乎表明了这一点)?我将如何以及在哪里添加它?

编辑:如果重要的话,gradle 版本是 1.10。

4

2 回答 2

1

正如@user149408 指出的 Gradle 版本(v1.10 与 v2.10)不匹配,我进一步挖掘了一点:

v0.7.0 的 gradle-git-plugin 提交指定使用的 Gradle 版本 (v1.11),因此使用 v1.10 构建工作正常。

因为 Gradle 插件总是使用 Gradle 构建compile localGroovy()并且compile gradleApi()来自 Gradle,所以如果它使用 Gradle 2.x 构建,则会导致 Groovy 不匹配错误。

  • 出了什么问题:任务 ':src:myproject:clone' 执行失败。java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/typehandling/ShortTypeHandling

事实上,Gradle v2.10 和 gradle-git v1.2.0 的组合运行良好。

一些示例build.gradle与问题中的结构相似。

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.ajoberstar:gradle-git:1.2.0'
    }
}

import org.ajoberstar.grgit.*

task clone << {
    File dir = new File('contrib/gs-spring-boot')
    if(!dir.exists()) {
        def grgit = Grgit.clone(dir: dir, uri: 'https://github.com/chenrui333/gs-spring-boot.git')
    }
    // TODO else (pull)
}

./gradlew clone会给你:

$ ls contrib/gs-spring-boot/
CONTRIBUTING.adoc   LICENSE.code.txt    LICENSE.writing.txt README.adoc         complete            initial             test

希望能帮助到你!

于 2017-07-18T13:31:12.420 回答
0

我已经设法解决了。

grgit-1.2.0 似乎依赖于 groovy。在/块中添加classpathgroovy 条目会导致不同的错误:buildscriptdependencies

Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:src:myproject:clone FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/home/me/src/myproject/build.gradle' line: 23

* What went wrong:
Execution failed for task ':src:myproject:clone'.
> java.lang.IncompatibleClassChangeError: the number of constructors during runtime and compile time for org.ajoberstar.grgit.auth.AuthConfig$Option do not match. Expected -1 but got 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 12.295 secs

进一步的研究表明,这可能源于版本不兼容(因为其他原因我坚持使用 Gradle 1.10)。

最终我通过回到 grgit-0.7.0 解决了这个问题。现在我的 git 任务工作了,并且 repo 被克隆了。

于 2017-07-18T12:33:59.763 回答