Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot output directory should be a task input not output #852

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jrodbx
Copy link
Collaborator

@jrodbx jrodbx commented May 15, 2023

We want Gradle's task invalidation logic to rerun tests when the snapshot output directory is changed, which was the motivation behind #206. However, by adding it as an output property, Gradle 8.0 now throws the following error:

A problem was found with the configuration of task ':sample:testReleaseUnitTest' (type 'AndroidUnitTest').
  - Gradle detected a problem with the following location: '/home/runner/work/paparazzi/paparazzi/sample/src/test/snapshots'.
    
    Reason: Task ':sample:spotlessKotlin' uses this output of task ':sample:testReleaseUnitTest' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':sample:testReleaseUnitTest' as an input of ':sample:spotlessKotlin'.
      2. Declare an explicit dependency on ':sample:testReleaseUnitTest' from ':sample:spotlessKotlin' using Task#dependsOn.
      3. Declare an explicit dependency on ':sample:testReleaseUnitTest' from ':sample:spotlessKotlin' using Task#mustRunAfter.
    
    Please refer to https://docs.gradle.org/8.1.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.

Spotless doesn't care about snapshots, and output side effects of a task don't necessarily == task outputs, so this fixes both.

Side note: This change specifically uses inputs.files(...), instead of inputs.dir(...), since the latter requires the folder to exist per Gradle conventions: https://docs.gradle.org/7.6.1/userguide/validation_problems.html#input_file_does_not_exist

@jrodbx jrodbx force-pushed the jrod/2023-05-15/input-not-output branch from 5b25e3a to 7c8bd69 Compare May 15, 2023 21:41
@@ -179,9 +179,11 @@ class PaparazziPlugin : Plugin<Project> {
test.inputs.files(nativePlatformFileCollection)
.withPropertyName("paparazzi.nativePlatform")
.withPathSensitivity(PathSensitivity.NONE)
test.inputs.files(snapshotOutputDir)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add "side note" as a comment here to prevent inadvertent future "optimizations"?


test.outputs.dir(reportOutputDir)
test.outputs.dir(snapshotOutputDir)
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a feeling this ambiguity comes from the fact that the same task can run in record and verify modes. In record mode the output is snapshots, and in verify mode snapshots are input and the output is reports. Does this mean that adding snapshotOutputDir as input/output should be based on the isRecordRun/isVerifyRun properties? (e.g. something like isRecordRun.map { if (it) snapshotOutputDir else "dummyNonExistentFolder" })?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants