kordamp / jandex-gradle-plugin

Jandex Gradle Plugin
Apache License 2.0
12 stars 6 forks source link

Jandex plugin breaks standalone Quarkus module Tests #29

Closed ghubstan closed 5 months ago

ghubstan commented 5 months ago

I have a mono-repo of Quarkus modules:

Module A (and A's QuarkusTests) can import/instantiate application scoped beans defined modules Y and Z, "if" the Y and Z build.gradle.kts files' plugins specs include:

id("org.kordamp.gradle.jandex") version "1.1.0"

But now I cannot compile (for dev/test) modules Y or Z (alone), unless I comment out // id("org.kordamp.gradle.jandex") version "1.1.0" from their build files.

I get Gradle error:

Reason: Task ':y-service:pluginUnderTestMetadata' uses this output of task ':y-service:jandex' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

Possible solutions:
1. Declare task ':y-service:jandex' as an input of ':y-service:pluginUnderTestMetadata'.
2. Declare an explicit dependency on ':y-service:jandex' from ':y-service:pluginUnderTestMetadata' using Task#dependsOn.
3. Declare an explicit dependency on ':y-service:jandex' from ':y-service:pluginUnderTestMetadata' using Task#mustRunAfter.

My multi-module app&test (A) works fine if I use the jandex plugin in child modules Y and Z. But I cannot work on child modules Y and Z in isolation if Y and Z are using the jandex plugin.

I am using quarkusPlatformVersion=3.8.3, Gradle version 8.7 (build files written in Kotlin DSL), JDK 21

I have searched around for reports of similar problem, but have found none. I can work around this by commenting/uncommenting the plugin def as needed, but would like better solution. Can anyone advise?

aalmiray commented 5 months ago

I'd suggest using an afterEvaluate block, checking for the existence of the given tasks by name and connect them if they are found, similarly as it's done here https://github.com/jreleaser/jreleaser/blob/3ccb2e4fcb0ab9510f8171eae1e20893d7dd0f97/plugins/jreleaser-tool-provider/jreleaser-tool-provider.gradle#L129

ghubstan commented 5 months ago

I'd suggest using an afterEvaluate block...

That seems to have resolved the issue.


afterEvaluate {
    var taskJandex = tasks.named("jandex")
    var taskPluginUnderTestMetadata = tasks.named("pluginUnderTestMetadata")
    if (taskJandex.isPresent && taskPluginUnderTestMetadata.isPresent) {
        taskPluginUnderTestMetadata.get().dependsOn(taskJandex)
    } else {
        println("One or both jandex related tasks are not present. Task pluginUnderTestMetadata.dependsOn(jandex).")
        println("Task jandex: $taskJandex")
        println("Task pluginUnderTestMetadata: $taskPluginUnderTestMetadata")
    }
}

Many thanks!

aalmiray commented 4 months ago

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