square / anvil

A Kotlin compiler plugin to make dependency injection with Dagger 2 easier.
Apache License 2.0
1.31k stars 82 forks source link

Use a different build directory per Gradle build for main-build projects #826

Closed RBusarow closed 10 months ago

RBusarow commented 10 months ago

We been getting flakes in CI like this one:

> Cannot access output property 'outputDir' of task ':gradle-plugin:generateGradleTestBuildConfig'. Accessing unreadable inputs or outputs is not supported. Declare the task as untracked by using Task.doNotTrackState(). [...]
   > Failed to create MD5 hash for file '/home/runner/work/anvil/anvil/gradle-plugin/build/generated/sources/buildConfig/gradleTest/com/squareup/anvil/plugin/buildProperties/BuildProperties.kt' as it does not exist.

These are happening because the projects in the main "anvil" build are technically part of two different Gradle builds -- the main/root one, and the one that's included by the :delegate build. Both of those builds are acting upon the same files, and Gradle doesn't share concurrency controls between its builds. So, we have a shared mutable state (their build directories) and every build has a chance of creating a race condition like the one above.

The fix is to have different directories, which are $projectDir/build/anvil-build and $projectDir/build/included-build.