gradle-avro-plugin icon indicating copy to clipboard operation
gradle-avro-plugin copied to clipboard

Output of a task generateAvroJava without explicit or implicit dependency

Open AleksanderBrzozowski opened this issue 2 years ago • 8 comments

Prerequisites

  • [x] Are you running the latest version of the plugin? (Check releases)
  • [x] Are you running a supported version of Gradle? (Check the README)
  • [x] Are you running a supported version of Apache Avro? (Check the README)
  • [x] Are you running a supported version of Java? (Check the README)
  • [x] Did you check to see if an issue has already been submitted?
  • [x] Are you reporting to the correct repository? If your schema doesn't work with the Apache Avro CLI tool either, it's not a problem with this plugin. Running your file through the CLIComparisonTest in the sample project under the test-project directory can help diagnose this.
  • [x] Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Describe the bug

I have kotlin project where I am using avro plugin alongside ktlint (kotlint linter). When I run build, following log message appears:

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/aleksander.brzozowsk/IdeaProjects/education/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.

To Reproduce

Steps to reproduce the behavior:

The example repository with minimum configuration is available here.

Expected behavior

Log message should not appear. It should be fixed either in avro plugin or in ktlint plugin.

Environment (please complete the following information):

  • Gradle Version [7.4.1]
  • Apache Avro Version [-]
  • Gradle-Avro Plugin Version [1.3.0]
  • Java Version [11.0.7]
  • OS: [Mac OS X Big Sur]

AleksanderBrzozowski avatar Apr 06 '22 11:04 AleksanderBrzozowski

Thank you for the detailed issue report. I especially appreciate the example repository. I'll investigate the cause and get back to you.

davidmc24 avatar Apr 06 '22 12:04 davidmc24

As stated in the gradle docs, this occurs when one task depends on another without an implicit or explicit dependency.

As a workaround until a fix is in place, you can explicitly declare a dependency between the tasks in your build. For the example repository, this would be:

runKtlintCheckOverMainSourceSet.dependsOn generateAvroJava

gradle-avro-plugin has no way to be aware of all tasks that may use the files it generates.

Next, I'll try to figure out the ktlint plugin is using the generated source dir, and why Gradle isn't treating it as an implicit dependency.

davidmc24 avatar Apr 06 '22 19:04 davidmc24

Yes, you are right, I fixed this with:

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

I think that the plugin is using generated source dir, because we added it to main source sets:

sourceSets {
    main {
        java {
            srcDir "${buildDir}/generated-main-avro-java/"
        }
    }
}

There is an option to exclude (filter) folder from linting, but I tried it, and it didn't work :)

AleksanderBrzozowski avatar Apr 06 '22 19:04 AleksanderBrzozowski

It appears that the kotlin plugin (that ktlint depends on) considers all Java source sets as kotlin source sets. The filtering is applied to all source sets. Still going to look a bit more to see why it's not considering it an implicit dependency

davidmc24 avatar Apr 06 '22 20:04 davidmc24

@davidmc24 wow, thanks ;) Let me know if you will find something :)

AleksanderBrzozowski avatar Apr 07 '22 06:04 AleksanderBrzozowski

Unfortunately, I wasn't able to make any real progress on that front. There probably is something that the ktlint plugin could do to better handle generated source directories, but I can't figure out what.

davidmc24 avatar Apr 07 '22 14:04 davidmc24

@davidmc24 Maybe I should create the same issue, but in ktlint repository? Maybe they will find something more? ;)

AleksanderBrzozowski avatar Apr 08 '22 14:04 AleksanderBrzozowski

Yeah, that might be more likely to get results.

davidmc24 avatar Apr 08 '22 15:04 davidmc24