-1

Gradle throws a NoClassDefFoundError when trying to execute a grgit task.

Start of 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

Output:

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

Line 20 is the call to Grgit.clone().

Do I need to add groovy as a build dependency (which the error message seems to indicate)? How and where would I add it?

EDIT: gradle version is 1.10, if it matters.

user149408
  • 5,385
  • 4
  • 33
  • 69
  • Have you missed `apply plugin: 'groovy'`? – Rao Jul 18 '17 at 04:05
  • Adding `apply plugin: 'groovy'` gives me `Could not find property 'plugin' on project ':src:myproject'` for that line. NB: the omitted parts of `build.gradle` contain no reference to anything related to grgit, so if a required line is not in the snippet, it’s safe to assume it’s nowhere in the file. – user149408 Jul 18 '17 at 10:37
  • @user149408, why does your error is for task `':src:myproject:clone'`, I mean two levels of error, can you also run `./gradlew tasks --all` for me? – chenrui Jul 18 '17 at 11:52
  • @chenrui Output is here: https://pastebin.com/TUX52Vzb – user149408 Jul 18 '17 at 12:08

2 Answers2

1

As @user149408 pointed out the Gradle version (v1.10 vs v2.10) mismatch, I dug a little bit further:

gradle-git-plugin commit for v0.7.0 specifies the Gradle version used (v1.11), so the build with v1.10 works fine.

Because the Gradle plugin always built with compile localGroovy() and compile gradleApi() which comes from Gradle, then if it builds with Gradle 2.x, it would incur the Groovy mismatch error.

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

In fact, the combo of Gradle v2.10 and gradle-git v1.2.0 just works fine.

Some sample build.gradle similar structure as in the question.

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 would give you:

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

Hope it helps!

chenrui
  • 8,910
  • 3
  • 33
  • 43
0

I’ve managed to solve it.

grgit-1.2.0 appears to depend on groovy. Adding a classpath entry for groovy in the buildscript/dependencies block resulted in a different error:

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

Further research revealed that this might stem from a version incompatibility (as I’m stuck with Gradle 1.10 for other reasons).

Eventually I solved it by going back to grgit-0.7.0. Now my git task works and the repo gets cloned.

user149408
  • 5,385
  • 4
  • 33
  • 69