Delay plugin build until after javaCompile

I am writing a custom Java plugin to generate a report on annotated methods, using reflection. Some of the annotations I need to use are in our code, and will therefore not available as imports in the plugin until the compileJava task has run and the .jar files are built. I have defined my task as “dependsOn” the compileJava task, but gradle fails as it appears to try to build my task before the compileJava step runs, and fails on the missing import.


dependencies {
compile ‘org.reflections:reflections:0.9.11’
compile fileTree(dir: ‘…\build\libs’, include: ‘*.jar’)


public class MyPlugin implements Plugin {
public void apply(Project project) {
MyTask myTask = project.getTasks().create(“mytask”, MyTask.class);
Task javaCompileTask = project.getTasks().getByName(“compileJava”);

Is there a way to do this?

It is not possible to have the buildSrc project depend on build artifacts of the same build. The entire build essentially has a dependency on buildSrc, so this will always be an impossible cycle. In order for something like this to work, the annotations need to be isolated such that both buildSrc and the consuming projects of your current project can depend on the annotation project.

Makes sense. Thank you.