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

Support using Gradle Build Cache with Yarn tasks #205

Merged
merged 3 commits into from
Mar 21, 2017
Merged

Conversation

mark-vieira
Copy link
Contributor

@mark-vieira mark-vieira commented Mar 17, 2017

This pull request enables the ability for users of Yarn install and setup tasks to enable Gradle Build Cache support. This relies on relaxing incremental build checking to use only relative path checking so that task outputs creating on one machine (or workspace directory) can be reused somewhere else. Older versions of Gradle will behave the same and ignore @PathSensitive annotations.


This change is Reviewable

There's actually no need to track the yarn working directory as an input.
The only thing this affects is how we calculate the output directory. Since
we track the output directory explicitly this is unneeded. Removing this
also removes an absolute path from the task inputs, allowing the Gradle
build cache to work across different machines.
We should ignore absolute paths on task inputs unless absolutely necessary
in order to allow caching of tasks with the Gradle build cache across machines.
@srs
Copy link
Owner

srs commented Mar 19, 2017

Hi. Thanks for the pull. But I noticed the build's are failing. Possible to fix that?

This effectively disabled the validation done by using input annotations.
The result is the same behavior as using `TaskInputs.files` which is to
not validate that the input files are present and exist. While not preferable
this at least limits breaking existing users which might have a unique
configuration.
@mark-vieira
Copy link
Contributor Author

Sorry about that. The issue is that converting to using the input annotations enforced validation checks that the inputs API does not perform. Specifically, ensuring that input files exist. My guess is that this is only breaking the tests but I expect someone out in the wild might have a similar configuration (not using yarn.lock).

I've relaxed the validations to emulate with the old behavior was, which is just ignoring that input if the file doesn't exist. I'd suggest doing something more robust in the future but this should at least keep existing plugin users working.

@srs srs merged commit 58cad9b into srs:master Mar 21, 2017
@anuraaga
Copy link

anuraaga commented Aug 9, 2017

@mark-vieira I noticed this when updating the version of gradle-node-plugin - cool change. Just wondering, since this doesn't add @CacheableTask, does that mean it's expected for users to define their own yarn task to use build cache, e.g.

@CacheableTask
class CacheableYarnInstallTask extends YarnInstallTask {
}
project.tasks.create('cacheableYarn', CacheableYarnInstallTask.class);

@mark-vieira
Copy link
Contributor Author

Adding @CacheableTask would cause those tasks to get cached by default, which isn't necessarily what folks want. What you've put above is a perfectly fine solution. You can also do this in an ad-hoc manner.

yarn.outputs.cacheIf { true } 

@anuraaga
Copy link

anuraaga commented Aug 9, 2017

@mark-vieira Ah, didn't realize cacheIf works even for tasks without the annotation, learned a great trick!

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.

3 participants