quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.82k stars 2.69k forks source link

Intellij: Task sequence for task 'compileQuarkusGeneratedSourcesJava' not correct (Gradle, Kotlin, Multi-Module Project) #38996

Open mschorsch opened 8 months ago

mschorsch commented 8 months ago

Describe the bug

We use Quarkus, Kotlin and Gradle in our various projects.

In multi-module projects we get the following error in Intellij:

FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':app-editor-server:compileKotlin' (type 'KotlinCompile').
  - Gradle detected a problem with the following location: '/home/user1/development/sources/app-editor/app-editor-server/build/classes/java/quarkus-generated-sources'.

    Reason: Task ':app-editor-server:compileKotlin' uses this output of task ':app-editor-server:compileQuarkusGeneratedSourcesJava' 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 ':app-editor-server:compileQuarkusGeneratedSourcesJava' as an input of ':app-editor-server:compileKotlin'.
      2. Declare an explicit dependency on ':app-editor-server:compileQuarkusGeneratedSourcesJava' from ':app-editor-server:compileKotlin' using Task#dependsOn.
      3. Declare an explicit dependency on ':app-editor-server:compileQuarkusGeneratedSourcesJava' from ':app-editor-server:compileKotlin' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.6/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.
  - Gradle detected a problem with the following location: '/home/user1/development/sources/app-editor/app-editor-server/build/classes/java/quarkus-generated-sources/grpc'.

    Reason: Task ':app-editor-server:compileKotlin' uses this output of task ':app-editor-server:compileQuarkusGeneratedSourcesJava' 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 ':app-editor-server:compileQuarkusGeneratedSourcesJava' as an input of ':app-editor-server:compileKotlin'.
      2. Declare an explicit dependency on ':app-editor-server:compileQuarkusGeneratedSourcesJava' from ':app-editor-server:compileKotlin' using Task#dependsOn.
      3. Declare an explicit dependency on ':app-editor-server:compileQuarkusGeneratedSourcesJava' from ':app-editor-server:compileKotlin' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.6/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.
  - Gradle detected a problem with the following location: '/home/user1/development/sources/app-editor/app-editor-server/build/classes/java/quarkus-generated-sources/avdl'.

    Reason: Task ':app-editor-server:compileKotlin' uses this output of task ':app-editor-server:compileQuarkusGeneratedSourcesJava' 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 ':app-editor-server:compileQuarkusGeneratedSourcesJava' as an input of ':app-editor-server:compileKotlin'.
      2. Declare an explicit dependency on ':app-editor-server:compileQuarkusGeneratedSourcesJava' from ':app-editor-server:compileKotlin' using Task#dependsOn.
      3. Declare an explicit dependency on ':app-editor-server:compileQuarkusGeneratedSourcesJava' from ':app-editor-server:compileKotlin' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.6/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.
  - Gradle detected a problem with the following location: '/home/user1/development/sources/app-editor/app-editor-server/build/classes/java/quarkus-generated-sources/avpr'.

    Reason: Task ':app-editor-server:compileKotlin' uses this output of task ':app-editor-server:compileQuarkusGeneratedSourcesJava' 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 ':app-editor-server:compileQuarkusGeneratedSourcesJava' as an input of ':app-editor-server:compileKotlin'.
      2. Declare an explicit dependency on ':app-editor-server:compileQuarkusGeneratedSourcesJava' from ':app-editor-server:compileKotlin' using Task#dependsOn.
      3. Declare an explicit dependency on ':app-editor-server:compileQuarkusGeneratedSourcesJava' from ':app-editor-server:compileKotlin' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.6/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.
  - Gradle detected a problem with the following location: '/home/user1/development/sources/app-editor/app-editor-server/build/classes/java/quarkus-generated-sources/avsc'.

    Reason: Task ':app-editor-server:compileKotlin' uses this output of task ':app-editor-server:compileQuarkusGeneratedSourcesJava' 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 ':app-editor-server:compileQuarkusGeneratedSourcesJava' as an input of ':app-editor-server:compileKotlin'.
      2. Declare an explicit dependency on ':app-editor-server:compileQuarkusGeneratedSourcesJava' from ':app-editor-server:compileKotlin' using Task#dependsOn.
      3. Declare an explicit dependency on ':app-editor-server:compileQuarkusGeneratedSourcesJava' from ':app-editor-server:compileKotlin' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.6/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 15s

The error only occurs when compiling with the Intellij integrated function Rebuild Project. Compiling with ./gradlew build works without problems.

We were able to determine the following prerequisites for the error to occur in Intellij:

To workaround the problem we use:

subprojects {
   //...

    tasks.matching { it.name == "compileQuarkusGeneratedSourcesJava" }.configureEach {
        mustRunAfter(tasks.compileKotlin)
    }

   //...
}

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

So far I have not managed to create a small reproducer.

Output of uname -a or ver

Linux

Output of java -version

Java 17

Quarkus version or git rev

Quarkus 3.7.4

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle

Additional information

No response

quarkus-bot[bot] commented 8 months ago

/cc @geoand (kotlin), @glefloch, @quarkusio/devtools

mschorsch commented 8 months ago

Today we had a similar issue with the task compileJava and compileQuarkusGeneratedSourcesJava. So it seems not Kotlin specific. In all cases the error is that the order of the tasks ist not defined and this can lead to incorrect results.

I assume that the order of compileQuarkusGeneratedSourcesJava and Kotlin and Java compilation should be explicitly defined in the Gradle Plugin.

mschorsch commented 8 months ago

Seems to be a problem with the local installation therefore closed.

mschorsch commented 8 months ago

After further investigation it is not a problem with the local installation.

The problem only occurs when org.gradle.parallel=true is set in the gradle.properties file.

mschorsch commented 8 months ago

@geoand @glefloch @quarkusio/devtools

I've managed to create a small reproducer.

  1. Download the attached reproducer project (reproducer.zip)
  2. Open the reproducer with Intellij
  3. Build > Rebuild Project in Intellij

The following requirements must be met for the error to occur:

Once again, the error only seems to occur in Intellij itself. However, it may still be a sequence problem with the Gradle tasks, which for whatever reason only occurs in Intellij.

mschorsch commented 6 months ago

@aloubyansky: You have been mentioned in other issues in connection with Gradle and the Quarkus plugin so I hope you can help here.

ryanlewis commented 6 months ago

Experiencing a similar problem, meeting the requirements listed by @mschorsch

Following workaround seemed to work for me

tasks.withType<KotlinCompile> {
    mustRunAfter("quarkusGenerateCode", "quarkusGenerateCodeDev")
}
BrianSetz commented 5 months ago

I experienced something similar and it seems to be on the IntelliJ side. Note that my multi module gradle projects do not have org.gradle.parallel=true set.

What fixed it for me is deleting .gradle / .idea folders and reimporting the project. It's almost like Build / Rebuild project generated the wrong set/order of gradle tasks.

rolfth commented 3 months ago

I have seen the same issue when building in Visual Studio Code. But don't know what triggered the behavior.

Also #34430 reports the same issue.