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?