尝试执行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,如果它很重要。
您是否错过了'apply plugin:'groovy''? – Rao
添加'apply plugin:'groovy''给了我'该项目的'无法找到属性'插件':src:myproject''。注意:'build.gradle'的省略部分不包含任何与grgit相关的任何引用,所以如果所需的行不在代码片段中,则可以安全地假定它不在文件中。 – user149408
@ user149408,为什么你的错误是针对任务''的:src:myproject:clone'',我的意思是两个级别的错误,你还可以为我运行'./gradlew tasks --all'吗? – chenrui