Task "jandex" up-to-date check passes as long as the jandex.idx exists (and will not rebuild for new source)
jskillin-idt opened this issue · comments
Description:
The "jandex" task will build the "jandex.idx" file once, and then appears to never build it again as long as it exists. At initial glance in the source, the "@InputFiles" field appears to be wired up to an empty file collection, which, if I understand Gradle correctly, implies that as long as the output exists, the task will pass the up-to-date check.
The "jandex" task ought to rebuild the "jandex.idx" when the class files that Jandex is indexing have changed.
Reproducer:
https://github.com/jskillin-idt/kordamp-jandex-gradle-plugin-issues-24
Steps to reproduce:
- Clone the repo and check out the "hi" branch.
- Run
./gradlew build
and observe the "printMethods" task gives the list of methods present insrc/main/java/com/sample/Test.java
- Without any further action, immediately check out the "hello" branch and run
./gradlew build
again. Observe the "printMethods" task continues to give the old list of methods, despitesrc/main/java/com/sample/Test.java
having been rewritten with new methods.
(Reproducer added)
The reproducer is really helpful. 👍 .
When I run it:
./gradlew build --console=PLAIN
first run:
Starting a Gradle Daemon (subsequent builds will be faster)
> Configure project :
Jandex Gradle plugin 1.0.0. Consider becoming a patron at https://www.patreon.com/aalmiray
> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :compileTestJava NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test NO-SOURCE
> Task :check UP-TO-DATE
> Task :jandex
> Task :jar
> Task :assemble
> Task :printMethods
void <init>()
void sayHi()
> Task :build
BUILD SUCCESSFUL in 14s
4 actionable tasks: 4 executed
git checkout hello
and second run ./gradlew build --console=PLAIN
:
> Configure project :
Jandex Gradle plugin 1.0.0. Consider becoming a patron at https://www.patreon.com/aalmiray
> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :jandex UP-TO-DATE
> Task :jar
> Task :assemble
> Task :compileTestJava NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test NO-SOURCE
> Task :check UP-TO-DATE
> Task :printMethods
void <init>()
void sayHi()
> Task :build
BUILD SUCCESSFUL in 729ms
The Task :jandex UP-TO-DATE
is wrong in the second run.
I am not an expert, but I think that the problem is that when resolvedProcessDefaultFileSet
is true (which is the default), the folder build/classes/java/main
is not treated as being part of the input, because resolveSources()
is called too late (configuration is already done and the folder is not part of the input):
My current work-around is to add the folder as additional input for the jandex task:
tasks.named('jandex') {
inputs.files(sourceSets.findByName('main').output.classesDirs*.absolutePath.flatten())
.withPropertyName('sourceFiles')
.withPathSensitivity(PathSensitivity.RELATIVE)
}