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.
/buildSrc/build.gradle
dependencies {
compile ‘org.reflections:reflections:0.9.11’
compile fileTree(dir: ‘…\build\libs’, include: ‘*.jar’)
}
/buildSrc/src/main/java/my/plugins/MyPlugin.java
public class MyPlugin implements Plugin {
@Override
public void apply(Project project) {
MyTask myTask = project.getTasks().create(“mytask”, MyTask.class);
Task javaCompileTask = project.getTasks().getByName(“compileJava”);
myTask.dependsOn(javaCompileTask);
}
}
Is there a way to do this?