Skip to content

Commit

Permalink
Don't use input/outputs for tasks
Browse files Browse the repository at this point in the history
As of Gradle 4.2 [1], when execution of a task begins, any "stale" outputs
will be deleted. All files under build and any declared outputs are
considered managed by Gradle. If other files happen to be in there,
Gradle will delete them.

The reset task did not declare any outputs, but created the
build/gitPublish directory and cloned the repo in there. When the copy
task rolls around, which is a built in task with declared
inputs/outputs, it sees some that cloned repo as stale files in its
output directory, since the copy task didn't put them there. Since they
are also under build, Gradle considers itself the owner and thinks it's
safe to delete them.

Since the inputs/outputs of the tasks in this plugin both overlap and
sometimes aren't clear files in / files out situations, it is easier for
now to drop using them altogether.

This commit drops the use of the Copy task, in favor of a ad-hoc task
that uses project.copy. This was the only task that had any
inputs/outputs declared before, so this issue should no longer be able
to present.

This fixes #35.

[1] https://docs.gradle.org/4.2/release-notes.html#safer-handling-of-stale-output-files
  • Loading branch information
ajoberstar committed Oct 21, 2017
1 parent f820ee9 commit 0093242
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ class GitPublishPlugin implements Plugin<Project> {
group = 'publishing'
description = 'Prepares a git repo for new content to be generated.'

// creates/clones the repo
outputs.dir(extension.repoDir)

// get the repo in place
doFirst {
Grgit repo = findExistingRepo(project, extension).orElseGet { freshRepo(extension) }
Expand Down Expand Up @@ -125,12 +122,16 @@ class GitPublishPlugin implements Plugin<Project> {
}

private Task createCopyTask(Project project, GitPublishExtension extension) {
Task task = project.tasks.create(COPY_TASK, Copy)
Task task = project.tasks.create(COPY_TASK)
task.with {
group = 'publishing'
description = 'Copy contents to be published to git.'
with extension.contents
into { extension.repoDir }
doLast {
project.copy {
with extension.contents
into { extension.repoDir }
}
}
}
return task
}
Expand All @@ -140,8 +141,6 @@ class GitPublishPlugin implements Plugin<Project> {
task.with {
group = 'publishing'
description = 'Commits changes to be published to git.'
// creates commit in the repo
outputs.dir(extension.repoDir)
doLast {
Grgit repo = extension.repo
repo.add(patterns: ['.'])
Expand Down

1 comment on commit 0093242

@wolfs
Copy link

@wolfs wolfs commented on 0093242 Oct 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.