JLLeitschuh / ktlint-gradle

A ktlint gradle plugin
MIT License
1.45k stars 159 forks source link

Ktlint should not lint files generated on the fly #580

Open AleksanderBrzozowski opened 2 years ago

AleksanderBrzozowski commented 2 years ago

We have a project in which we use java classes generated from avro files. In this project, we also use ktlint to lint kotlin code.

When we run build, we see following warning in console:

Task :runKtlintCheckOverMainSourceSet
Execution optimizations have been disabled for task ':runKtlintCheckOverMainSourceSet' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '/Users/xyz/avro-ktlint-gradle/build/generated-main-avro-java'. Reason: Task ':runKtlintCheckOverMainSourceSet' uses this output of task ':generateAvroJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.4.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.

In order to get rid of this warning, we need to explicitly set dependency on generateAvroJava task, like this:

tasks.named("runKtlintCheckOverMainSourceSet").configure { dependsOn(":generateAvroJava") }

Problem was also reported to generate avro java plugin.

Is there any way to solve this problem on the plugin side?

dalewking commented 10 months ago

Any update on this? This keeps me from using the plugin.

shiveenp commented 5 months ago

Hello @wakingrufus just calling out that this seems to be a regression with the new JDK/Gradle version and has affected us as well.

wakingrufus commented 5 months ago

Hello @wakingrufus just calling out that this seems to be a regression with the new JDK/Gradle version and has affected us as well.

Hi, are you on the latest version of the plugin? I recently reworked how source sets are detected in a way that may have solved this. If it is still broken, a minimal reproducer would be very helpful to me to dig in further. Thanks.