0

I have a custom annotation processor which creates few classes. This is working fine in eclipse build and it generates java files with full package structure under ".apt_generated" folder.

String implName = "foo/bar/impl/" + annotatedElement.getSimpleName() + "Impl";
JavaFileObject jfo = filer.createSourceFile(implName, annotatedElement);
Writer writer = jfo.openWriter();
writer.write("package foo.bar.impl;\n\n");
writer.write("public class CustomImpl {}\n");
writer.close();

However this is not working with gradle build. Getting below error while building using Gradle.

Illegal name foo/bar/impl/CustomImpl javax.annotation.processing.FilerException: Illegal name foo/bar/impl/CustomImpl at com.sun.tools.javac.processing.JavacFiler.checkName(JavacFiler.java:495) at com.sun.tools.javac.processing.JavacFiler.checkNameAndExistence(JavacFiler.java:517) at com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:396) at com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:378)

Interestingly if we remove package path from file name, then Gradle build works. But creates all files in one folder without respecting the package structure.

Any idea why Gradle build is behaving like this?

vinodpthmn
  • 1,062
  • 14
  • 28
  • 1
    Have you tried "foo.bar.impl." instead of "foo/bar/impl/"? Examples I can find seem to point to this being a qualified package name, not a path (contrary to what I thought the official docs were trying to state) – Alex Hart Jul 15 '19 at 14:34
  • Thanks @AlexHart that worked!! I am wondering why '/' is not working for gradle but fine with eclipse?? any clue? – vinodpthmn Jul 17 '19 at 07:18

0 Answers0