1

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']
    }
}
user1428945
  • 339
  • 1
  • 13
  • It looks like `my.AnnotationProcessor` doesnt have a public no-args constructor - if this isn't the case, can you share its contents? – Colin Alworth Mar 17 '23 at 21:38
  • I did add a public no-arg constructor to `my.AnnotationProcessor`, it did not fix the error. – user1428945 Mar 17 '23 at 22:04
  • Sharing the code is going to help in looking for other issues, or reproducing the issue to make concrete suggestions. The `--add-opens` is not required by other annotation processors, so it shouldn't be needed here, and other annotation processors don't require it. I think this is less likely to help, but perhaps share the rest of the dependency setup as well (since it seems missing)? – Colin Alworth Mar 18 '23 at 02:34

0 Answers0