Task up-to-date checking

I thought I understood how up-to-date checks happen for task, but I seem to have been wrong…

I have a plugin which will optionally trigger adding the java-library plugin based on whether a certain block is used in my plugin’s DSL extension.

The project where my plugin is applied is not originally a java-library and has no sources of its own. My plugin “generates” sources and then links them into the project’s sourceSets.main.allJava.srcDir.

My understanding is that linking the output from my generation into the projects main source-set’s java dirs would be enough. But simply doing that, the project’s compile task is always skipped with NO_SOURCE.

Is it maybe a timing issue? My plugin applying java-library still happens during config phase, so it should be good. I print out a few seemingly important information about the project, but everything points to the compile should be triggered.

Copy dir `/home/sebersole/projects/playground/jakarta-transformer-plugin/build/tmp/testKit/testKit1691600008/shadowMulti/shadow/build/jakarta/transform/shadow/real/src/main/java` exists? : true

`sourceSet.main.allJava` -> /home/sebersole/projects/playground/jakarta-transformer-plugin/build/tmp/testKit/testKit1625958045/shadowMulti/shadow/src/main/java:/home/sebersole/projects/playground/jakarta-transformer-plugin/build/tmp/testKit/testKit1625958045/shadowMulti/shadow/build/jakarta/transform/shadow/real/src/main/java

`(:shadow:compileJava).input.hasSourceFiles` - true
  1. “Copy dir” is where the generated sources go. Relatively, this is build/jakarta/transform/shadow/real/src/main/java
  2. The main source-set’s java dirs contains both the conventional dir (src/main/java) as well as this copy-dir. I tried setting the source-dirs to contain just the copy-dir thinking the empty src/main/java might be the problem. But I could not figure out how to completely replace the source-dirs or remove one
  3. “has sources” comes from tasks.compile.inputs.hasSourceFiles

What am I missing?

I was able to get this to work, though still confused…

What I had to do was to add the copy-dir to the JavaCompile task’s sources (JavaCompile#sources).

Isn’t JavaCompile configured by the java(-library) plugin to use sourceSet.allJava as its source?

I wonder if adding it to sourceSet.java would have worked. I don’t know how allJava is wired up, though I think that java should be wired up correctly.

Ah, good point. I never understood the point of sourceSet.java versus allJava.