Gradle annotation processor with ECJ compiler produces "Unable to get public no-arg constructor" error

144 views Asked by At

I'm trying to compile a gradle project with the ECJ compiler. I have an annotation processor in one of the projects, that the other projects depend on.

When ECJ attempts to run the annotation processor, it produces this error:

1. ERROR in C:\...\MyClass.java (at line 0)
        package my.package;
        ^
Internal compiler error: java.util.ServiceConfigurationError: javax.annotation.processing.Processor: my.AnnotationProcessor Unable to get public no-arg constructor at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:582)

I tried adding a public, no-arg constructor to the annotation processor and it didn't fix the error. I also tried adding --add-opens java.base/java.util=ALL-UNNAMED to the commandline arguments, that also did not work.

This is the gradle configuration:

configurations {
    ecj
}
dependencies {
    ecj 'org.eclipse.jdt:ecj:3.25.0'
}
tasks.withType(JavaCompile) {
    options.headerOutputDirectory.convention(null) //To stop gradle from passing in -h, which ecj doesn't recognize
}
compileJava {
    options.fork = true
    options.forkOptions.with {
    executable = 'java'
    jvmArgs = ['-classpath', project.configurations.ecj.asPath, '--add-opens', 'java.base/java.util=ALL-UNNAMED', 'org.eclipse.jdt.internal.compiler.batch.Main']
    }
}
0

There are 0 answers