kordamp / jandex-gradle-plugin

Jandex Gradle Plugin
Apache License 2.0
13 stars 7 forks source link

Task "jandex" up-to-date check passes as long as the jandex.idx exists (and will not rebuild for new source) #24

Closed jskillin-idt closed 4 months ago

jskillin-idt commented 1 year ago

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:

  1. Clone the repo and check out the "hi" branch.
  2. Run ./gradlew build and observe the "printMethods" task gives the list of methods present in src/main/java/com/sample/Test.java
  3. 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, despite src/main/java/com/sample/Test.java having been rewritten with new methods.
jskillin-idt commented 1 year ago

(Reproducer added)

jmini commented 1 year ago

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):

https://github.com/kordamp/jandex-gradle-plugin/blob/8b9f8795c02034dbf73af9d18b77e60afa76cb21/src/main/groovy/org/kordamp/gradle/plugin/jandex/tasks/JandexTask.groovy#L155-L157


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)
}
aalmiray commented 4 months ago

🎉 This issue has been resolved in v2.0.0 (Release Notes)