0

I have one simple application "Client" that uses some annotation, within it I am including the .jar for the annotation processor that I wrote, should write java class using JavaPoet to the console. The following are the configuration for build.gradle I did in the "Client" app:

    repositories {
        mavenCentral()
        mavenLocal()
    }

    dependencies {
        compile fileTree(dir: 'libs', include: 'AnnotationProcessor-1.0-SNAPSHOT.jar')
        annotationProcessor fileTree(dir: 'libs', include: 'AnnotationProcessor-1.0-SNAPSHOT.jar')
        compile group: 'com.squareup', name: 'javapoet', version: '1.13.0'
    }

I have enabled the annotation processor in the project and given the fully qualified path to this annotation processor also. However, when I do a gradle build, the annotation processor runs and I get:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> java.lang.NoClassDefFoundError: com/squareup/javapoet/MethodSpec

Not sure what could I be doing wrong here.

CrazyCoder
  • 350,772
  • 137
  • 894
  • 800

1 Answers1

0

I was able to resolve this particular issue by publishing the annotation processor jar to local maven by including the following in its build.gradle:

apply plugin: "maven-publish"

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

Executing: ./gradlew publishToMavenLocal published it to maven local. And then, now the client project's build.gradle is as below:

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile fileTree(dir: 'libs', include: 'AnnotationProcessor-1.0-SNAPSHOT.jar')
    annotationProcessor('org.example:AnnotationProcessor:1.0-SNAPSHOT')
}

That resolved this issue.