IDEA re-compile deletes build system artifacts
I am working on eliminating a build step in our system for daily development work. We use gradle and IDEA in the following way.
- gradle build creates all the module artifacts and outputs them to the same module output directories as used by IDEA.
- gradle idea plugin is used to create create the IDEA project that mirrors the gradle project.
- IDEA is used for launching the application and debugging.
- IDEA is used for recompile of files in order to hot-swap the changes into the running JVM while debugging.
The problem is that typically for this to work requires two full compiles, one from gradle and one from IDEA. The IDEA compile seems to be required to fill IDEA's build cache so it knows all the files that gradle just generated are up-to-date with the sources. If the IDEA compile is skipped the application will launch just fine with the gradle generated artifacts, but the first file recompiled from IDEA will fail if IDEA does not also first build all the artifacts itself.
I can see the problem behavior without launching the application from IDEA. Here is the behavior I see with the interaction between the gradle and IDEA builds.
- Build project from gradle to output directory.
- Change one file in IDEA and recompile it.
- The compile fails and all artifacts for the module have been removed from the output directory by IDEA.
- Build project again from gradle and fill the output directory with fresh artifacts.
- Recompile the file from IDEA. Now the compile works even though a full IDEA project build was not attempted.
From this behavior it seems like under some conditions the IDEA build cache may consider the gradle generated artifacts as up-to-date since the second recompile attempt does not fail even though IDEA did not generate them.
Is there some way to prevent IDEA from removing the gradle built artifacts or considering them as up-to-date when recompiling a changed file?
I have also experimented with importing the gradle build into IDEA instead of using the gradle idea plugin, but the same issue occurs. The build contains steps that generate source files and weave output files that are built into gradle but the IDEA build is unaware of. This make doing an IDEA build without first doing a gradle build infeasible.
Please sign in to leave a comment.
No, this behavior is by design, IntelliJ IDEA cannot reuse class files compiled by other build systems (Ant, Maven, Gradle). It will not have the incremental compiler caches needed for Build action, therefore Rebuild will be performed if you share the output folders.
We do not recommend using the same output folders, IntelliJ IDEA uses different output folders by default, see https://stackoverflow.com/a/46035904/104891.