2017-07-17 67 views
-1

尝试执行grgit任务时,Gradle抛出NoClassDefFoundError。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,如果它很重要。

+0

您是否错过了'apply plugin:'groovy''? – Rao

+0

添加'apply plugin:'groovy''给了我'该项目的'无法找到属性'插件':src:myproject''。注意:'build.gradle'的省略部分不包含任何与grgit相关的任何引用,所以如果所需的行不在代码片段中,则可以安全地假定它不在文件中。 – user149408

+0

@ user149408,为什么你的错误是针对任务''的:src:myproject:clone'',我的意思是两个级别的错误,你还可以为我运行'./gradlew tasks --all'吗? – chenrui

回答

0

我已经设法解决它。

grgit-1.2.0似乎依赖于时髦。添加在buildscript/dependenciesclasspath条目常规产生了不同的错误:

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 

进一步的研究表明,这可能从一个版本不兼容干(如我坚持用摇篮1.10出于其他原因)。

最终我回到grgit-0.7.0来解决它。现在我的git任务可以工作,并且repo被克隆。

+0

你应该尝试提高积压的任何“升级gradle”卡的优先级;-) –

1

正如@ user149408指出摇篮版(V1.10 VS V2.10)不匹配,我挖得远一点:

gradle-git-plugin commit for v0.7.0指定用于(1.11)的摇篮版本,所以构建与v1.10工作正常。

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

  • What went wrong: Execution failed for task ':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 

希望它能帮助!