2017-07-17 14 views
-1

grditタスクを実行しようとすると、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を追加する必要がありますか?どのように追加すればいいですか?

EDIT:gradleバージョンが重要な場合1.10です。

+0

'apply plugin: 'groovy''を見逃しましたか? – Rao

+0

'apply plugin: 'groovy''を追加すると、その行に'プロジェクト上で'プラグイン 'プラグインを見つけることができませんでした:src:myproject''が表示されます。注意: 'build.gradle'の省略された部分にはgrgitに関連するものは何も含まれていませんので、必要な行がスニペットに含まれていなければ、ファイルにはどこにもないと考えることができます。 – user149408

+0

@ user149408、あなたのエラーはなぜタスク '':src:myproject:clone''のためですか?私は2つのレベルのエラーを意味します。あなたは' ./gradlew tasks --all'を実行できますか? – chenrui

答えて

0

私はそれを解決することができました。

grgit-1.2.0はgroovyに依存するようです。 buildscript/dependenciesブロックでグルーヴィーなためclasspathエントリを追加すると、別のエラーが発生しました:

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タスクが動作し、レポがクローン化されます。

+0

バックログにある「アップグレード用のgradle」カードの優先度を試してみてください。 –

1

user149408はGradleのバージョン(V2.10対V1.10)のミスマッチを指摘@として、私はさらに少し掘っ:

gradle-git-plugin commit for v0.7.0は(V1.11)使用Gradleのバージョンを指定し、そうでビルド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 

を、それが役に立てば幸い!