'Gradle's compileJava fails to write .class files if cache is enabled and the resources output dir is the same as the classes output dir
Applies to gradle 7.0 and earlier.
Every second clean/build cycle, the .class files are not written to $buildDir/classes.
The problem appears only when:
- The project has a very few number of java files (1-2 files) and some resource files
sourceSets.main.java.outputDir == sourcesSets.main.java.output.resourceDir- cache is enabled for the
compileJavatask
The behavior is this:
- clean -> build: works,
.classfiles are written in$buildDir/classes - Repeat step 1: fails,
.classfiles are NOT written - Repeat 1: works ...
- etc...
Given these conditions, the problem does not occur if either of the following is true:
- Disabling cache globally or for the
compileJavatask - The resources output directory is different than the
classesDir - The are no resources
- The project being build is larger (some timing issue obviously).
The problem happens randomly to other small sub-projects at different machines and at random times. I have searched for days and have not found any similar issue mentioned elsewhere so any hint will be very helpful.
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
