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

Install GJF hook using a gradle task, rather than a gradlew hack. #298

Merged
merged 3 commits into from Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions build.gradle
Expand Up @@ -38,6 +38,7 @@ subprojects { project ->
errorproneJavac deps.build.errorProneJavac
}
project.tasks.withType(JavaCompile) {
dependsOn(installGitHooks)
Copy link
Contributor

Choose a reason for hiding this comment

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

out of curiosity, does this task cache correctly? Or just cheap enough to run every time?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I see here: https://docs.gradle.org/current/userguide/build_cache.html#sec:task_output_caching_details

Some tasks, like Copy or Jar, usually do not make sense to make cacheable because Gradle is only copying files from one location to another. It also doesn’t make sense to make tasks cacheable that do not produce outputs or have no task actions.

I wonder if there's a friendlier way to handle this, such as using the spotless gradle plugin

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This won't be cached, but involves only copying a single 358 bytes file, so checking the cache would not be appreciably faster, I think :) (and makes sure the hook gets re-added if the user removes it somehow). Is there a problem with it I am not seeing?

options.compilerArgs += [
"-Xlint:unchecked",
"-Xlint:rawtypes",
Expand Down Expand Up @@ -71,3 +72,16 @@ subprojects { project ->
googleJavaFormat {
toolVersion = "1.6"
}

////////////////////////////////////////////////////////////////////////
//
// Google Java Format pre-commit hook installation
//

tasks.register('installGitHooks', Copy) {
from(file('config/hooks/pre-commit-stub')) {
rename 'pre-commit-stub', 'pre-commit'
}
into file('.git/hooks')
fileMode 0777
}
10 changes: 0 additions & 10 deletions config/hooks/install-pre-commit

This file was deleted.

3 changes: 0 additions & 3 deletions gradlew
@@ -1,8 +1,5 @@
#!/usr/bin/env sh

# added manually
./config/hooks/install-pre-commit

##############################################################################
##
## Gradle start up script for UN*X
Expand Down