Skip to content

Commit

Permalink
patch: Fix no such file or directory during commit
Browse files Browse the repository at this point in the history
Gradle fairly aggressively tries to cleanup stale output files, with
the goal of reliable build caching to avoid the need to run "./gradlew
clean". However, this is problematic for tasks that have overlapping
output directories, as it makes it difficult for Gradle to track
what's stale.

In a prior version we added the @UntrackedTask annotation to all of
the publish tasks to avoid Gradle's state tracking. However, we use
the built-in Gradle Copy task for one part of our chain, which does
not have that annotation.

In cases where the .gradle directory was not present, we would see the
repository directory get deleted after the gitPublishCopy task ran,
because Gradle thought it was stale. In other cases it seemed to be
fine.

While I don't understand the details of how Gradle makes those
stale/fresh decisions, particularly in the absence of the .gradle
directory, it seems the key is using the runtime method equivalent of
the @UntrackedTask annotation (Task.doNotTrackState) to tell Gradle
not to do its state tracking for this one task.

We could still have issues in the future, but this seems to get us
over the immediate hurdle.

Fixes #99
  • Loading branch information
ajoberstar committed Aug 14, 2022
1 parent ba61944 commit 7aa20e6
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ private TaskProvider<Copy> createCopyTask(Project project, GitPublication public
task.setDescription("Copy " + publication.getName() + " publication contents to be published to git.");
task.with(publication.getContents());
task.into(publication.getRepoDir());

// do not track state added in Gradle 7.3
if (GradleVersion.version("7.3").compareTo(GradleVersion.current()) <= 0) {
task.doNotTrackState("Tracked by Git instead");
}
});
}

Expand Down

0 comments on commit 7aa20e6

Please sign in to comment.