Lukas Kraushofer
09/20/2024, 5:45 AMorg.gradle.internal.execution.WorkValidationException: A problem was found with the configuration of task ':yedi-domain:kaptKotlin' (type 'KaptWithoutKotlincTask').
- Gradle detected a problem with the following location: '/data/home/agent-02/agent/work/7bfe31a37ea5b299/idoc-model/build/libs/idoc-model-5.24.40.1-RC-gradle-fix-1.jar'.
Reason: Task ':domain:kaptKotlin' uses this output of task ':idoc-model:sourcesJar' 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 ':idoc-model:sourcesJar' as an input of ':domain:kaptKotlin'.
2. Declare an explicit dependency on ':idoc-model:sourcesJar' from ':domain:kaptKotlin' using Task#dependsOn.
3. Declare an explicit dependency on ':idoc-model:sourcesJar' from ':domain:kaptKotlin' using Task#mustRunAfter.
For more information, please refer to <https://docs.gradle.org/8.4/userguide/validation_problems.html#implicit_dependency> in the Gradle documentation.
What can I do to insure that the module idoc-model, especially the tasks sourcesJar, run before domain:kaptKotlin?
We tried something like
afterEvaluate {
tasks.named("kaptKotlin") {
dependsOn(":idoc-model:sourcesJar")
}
}
in the domain build.gradle file, which worked sometimes on the build pipeline but did not work locally under special circumstances (starting Spring Boot in IntelliJ). To make it work locally again we had to change the depending task from :idoc-model:sourcesJar to :idoc-model:build
Any thoughts on how to tackle this problem?Javi
09/20/2024, 9:55 AMdependOn and related ones are patches. The real issue is those tasks are not setting the input/outputs correctly.Javi
09/20/2024, 9:57 AMJavi
09/20/2024, 9:59 AMLukas Kraushofer
09/20/2024, 10:01 AMJavi
09/20/2024, 10:03 AMit is not good that one project depends on the task from another project
Javi
09/20/2024, 10:04 AMJavi
09/20/2024, 10:04 AMLukas Kraushofer
09/20/2024, 10:10 AM// idoc-model build.gradle
plugins {
id 'org.unbroken-dome.xjc'
}
xjc {
srcDirName = 'resources'
}
task sourcesJar(type: Jar) {
duplicatesStrategy = 'include'
}
and
// domain build.gradle
dependencies {
implementation project(':idoc-model')
implementation "com.querydsl:querydsl-jpa"
kapt "com.querydsl:querydsl-apt:jpa
// ...
}
afterEvaluate {
tasks.named("kaptKotlin") {
dependsOn(":idoc-model:sourcesJar")
}
}Lukas Kraushofer
09/20/2024, 10:12 AM.xsd files which are transformed into java classesLukas Kraushofer
09/20/2024, 10:12 AM:domainLukas Kraushofer
09/20/2024, 10:13 AM:domain:kaptKotlin presumable needs these classesJavi
09/20/2024, 10:20 AMLukas Kraushofer
09/20/2024, 10:29 AMxjc and the task :xjcGenerate which is part of gradle buildJavi
09/20/2024, 10:32 AMLukas Kraushofer
09/20/2024, 6:55 PM:idoc-model module and the :domain module uses themVampire
09/20/2024, 7:38 PMdependsOn where on the left-hand side is not a lifecycle task is a code smell and as Javi said more a sign that task outputs are not wired properly to task inputs, the possible solutions in that message are actually all just duct-tape and not a proper solution in practically all cases
• afterEvaluate is highly discouraged. The main gain you get from using it are timing problems, ordering problems, and race conditions. It is like using SwingUtilities.invokeLater or Platform.runLater to "fix" a GUI problem. It just does symptom treatment, delaying the problem to a later, harder to reproduce, harder to debug, and harder to fix point in time.
• One of the most usual cases for this error are overlapping or wrongly declared outputs, so for example task A and task B both have directory X as output directory and write a file into it, then task C depends on outputs of A and you get that error message for B and C as due to the overlapping outputs the files in X are considered output for both, A and B wrongly.
• The other most usual case for this error is, if you actually do not wire task outputs to task inputs properly, or do not properly and safely share things between projects, but configure paths manually and thus missing task dependencies.
• What makes me 🤔 is, idoc-model-5.24.40.1-RC-gradle-fix-1.jar does not look to me like something a task called sourcesJar should produce, because a sourcesJar typically generates a file ending with -sources.jar, so maybe indeed somehow the outputs of your sourcesJar task are wrong.
• But as Javi said, it is hard to give concrete advice without seeing the project or at least an MCVE