2

I'm creating a gradle plugin that uses gson, but when I use the plugin at my client it throws this java.lang.NoClassDefFoundError: com/google/gson/Gson I expect I am linking my dependencies in the plugin in a wrong way, but i'm not quite sure so any help would be great.

The build.gradle in the plugin

group 'nl.daanluttik.gradle'
version '0.1'

apply plugin: 'java'
apply plugin: 'maven' // the plugin to distribute to maven

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'com.google.code.gson', name: 'gson', version: '1.7.2'
    compile gradleApi()/*The gradle plugin api*/
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

//To distribute to maven
uploadArchives {
    repositories {
        mavenLocal()
    }
}

A segment of the buildgradle in the client project

buildscript {
    repositories {
        mavenLocal()
    }
    dependencies {
        classpath group: 'nl.daanluttik.gradle', name: 'peach', version: '0.1'
    }
}
Daan Luttik
  • 2,781
  • 2
  • 24
  • 37
  • 1
    Is this really the first error? I most often see `NoClassDefFoundError` (in contrast to `ClassNotFoundException`) if some static initializer threw some exception and because of that the class could not be loaded and is not available later on. – Vampire Apr 30 '16 at 13:25
  • @BjörnKautler You are completely right. I will change it – Daan Luttik Apr 30 '16 at 13:28
  • Great, I made the commen an answer so you can act on it accordingly :-) – Vampire Apr 30 '16 at 13:30
  • can you take a look in the pom.xml published with your plugin to your mavenLocal? does it contain the gson dependency? – RaGe Apr 30 '16 at 14:43
  • did you try adding mavenCentral() to the buildscript section of your client project? – RaGe Apr 30 '16 at 14:43
  • @RaGe if I add mavenCentral() to the buildscript I already get 'NoClassDefFoundError: com/google/gson/Gson' during gradle's sync task. – Daan Luttik Apr 30 '16 at 14:53
  • @RaGe I did some searching and I found that it doesn't contain a pom.xml It does have an ivy-01.xml file that shows the dependency but I don't know if that counts. – Daan Luttik Apr 30 '16 at 15:05
  • you're using the maven plugin but you're producing an ivy repo descriptor? How?! – RaGe Apr 30 '16 at 18:10
  • @RaGe I dont know. Everything is in the given build.gradle – Daan Luttik Apr 30 '16 at 18:13
  • @DaanLuttik Did you ever figure this out? – neu242 Apr 30 '19 at 12:22
  • @neu242 I think just did a workaround. I finished this project over 2 years ago and no longer have access to the repository, so I can't check. – Daan Luttik Apr 30 '19 at 12:34

2 Answers2

0

Is this really the first error? I most often see NoClassDefFoundError (in contrast to ClassNotFoundException) if some static initializer threw some exception and because of that the class could not be loaded and is not available later on.

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • If I run the plugin with --info and --debug I still don't see any error preceding 'java.lang.NoClassDefFoundError' so I still have no idea where the problem comes from or how to solve it. – Daan Luttik Apr 30 '16 at 13:36
  • Ah, sorry, then I misunderstood you. From the comment I thought that was your problem. – Vampire Apr 30 '16 at 13:47
  • Thats ok, I meant that I'd change the problem description. The source of the problem is still a mystery to me. – Daan Luttik Apr 30 '16 at 13:49
0

Your missing the pom file with your dependencies. If it's just java then you can easily use the maven-publish which will generate the pom for you correctly.

apply plugin: 'maven-publish'

publishing {
    publications {
        maven(MavenPublication) {
            groupId 'nl.daanluttik.gradle'
            artifactId 'peach'
            version '0.1'

            from components.java
        }
    }
}

Then you can publish to the repositories (default local only) with gradle publish

Reference: https://docs.gradle.org/current/userguide/publishing_maven.html

JBirdVegas
  • 10,855
  • 2
  • 44
  • 50