[GRADLE-3428] Incremental Java compilation changing static final field does not always trigger re-compilation of dependent classes Created: 05/Apr/16  Updated: 10/May/16  Resolved: 10/May/16

Status: Resolved
Project: Gradle
Affects Version/s: 2.11
Fix Version/s: 2.14-rc-1

Type: Bug
Reporter: Eric Wendelin Assignee: Eric Wendelin
Resolution: Fixed Votes: 0

Attachments: File IncrementalJava.jar     File SimpleIncrementalIssue.jar    
Issue Links:
Related to GRADLE-3431 Gradle should warn user given sourceS... Resolved


From Jerome Dochez @ Google:

Please find attached a small project reproducing the incremental java compilation we encountered.
if you build/run the program you will see two values printed by the main.

then change the static final field value located in DepTwo class, do a build assemble, only the DepTwo class will be recompiled, the Main class which imports the static final field (inlined by the javac compiler) will not.

If you run the example again, you will see the old value.

It works fine if the files are in the same source folder, but not if the files are in different folder.
There is also a slightly more complicated example (currently commented) that is not working right now (using a different sourceSets altogether).

This is a big deal for us as it has quite a noticeable impact on the InstantRun performance especially on Windows where I/O is well sub optimal...

Comment by Eric Wendelin [ 07/Apr/16 ]

I found a small problem with the example that causes the problematic behavior.

I’ve highlighted the mismatch that, when corrected, allows Java incremental compilation to behave “correctly”. If one removes the extra java/ dir or changes the sourceSet sourceDir to ‘src/java/java’, then only changing the static final field in DepTwo correctly updates the Main.class put in build/libs/IncrementalJava-1.0-SNAPSHOT.jar and the new value is output when running Main.

File tree contained in the IncrementalJavaCompile.jar
├── build.gradle
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── java
│ └── java (<--- extra java/ directory here)
│ └── com
│ └── google
│ └── jedo
│ └── IncDep
│ └── DepTwo.java
├── main
│ └── java
│ └── com
│ └── google
│ └── jedo
│ └── IncrementalJava
│ ├── DepOne.java
│ └── Main.java

apply plugin: ‘java’
sourceSets {
main {

{ srcDir 'src/java' srcDir 'src/main/java' }


{ //enable incremental compilation options.incremental = true }
Comment by Eric Wendelin [ 07/Apr/16 ]

I consider this behavior of Gradle unexpected, so I have opened a new issue that suggests we warn users given a scenario like this: https://issues.gradle.org/browse/GRADLE-3431

Comment by Eric Wendelin [ 07/Apr/16 ]

Based on my comments on this issue.

I'm told there is a more complicated case where incremental java compilation fails. I'd love to hear more and have a complete example to look into there. If we get that, then we should reopen this issue.

Comment by Eric Wendelin [ 20/Apr/16 ]

Jerome provided a new example that does not work as intended

Generated at Wed Jun 30 12:48:34 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.