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

Do not mark entire root directory as input for git hook task #545

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

Conversation

rafalh
Copy link

@rafalh rafalh commented Oct 15, 2021

In PR #526 projectDir and rootDirectory were marked with @InputDirectory annotation to fix problems with Gradle configuration cache. But those annotations actually mean that addKtlintCheckGitPreCommitHook task is using entire root directory content as its input. This does not make much sense. Not only that but in Gradle 7.x it causes annoying output when addKtlintCheckGitPreCommitHook task is executed together with other tasks. In case of my project I have configured build task to depend on addKtlintCheckGitPreCommitHook (build.dependsOn addKtlintCheckGitPreCommitHook) and now when I do ./gradlew build in Gradle 7.x (I'm testing on 7.2 to be exact) I get a lot of output like below:

> Task :compileKotlin
Execution optimizations have been disabled for task ':compileKotlin' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '<PROJECT_DIR>/build/classes/kotlin/main'. Reason: Task ':addKtlintCheckGitPreCommitHook' uses this output of task ':compileKotlin' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '<PROJECT_DIR>/build/kotlin/compileKotlin'. Reason: Task ':addKtlintCheckGitPreCommitHook' uses this output of task ':compileKotlin' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.

addKtlintCheckGitPreCommitHook does not really depend on content of any of those directories so using @InputDirectory annotation is a mistake. Instead @Input annotation can be used with a String property (that's what JavaDoc of @InputDirectory annotation suggests for situations when directory content does not matter).
But I went with a simpler solution making projectDir and rootDir regular private Kotlin property that Gradle does not see and track. I think intention of PR #526 wasn't to make those values configurable as task inputs so there's no need to mark them with @Input annotation. There is also @Internal annotation but I do not see any benefit of using it here over private property.
I tested code with my project and no Execution optimizations have been disabled warnings were printed anymore.

If you like/accept my Pull Request please add hacktoberfest-accepted label so it can be counted as my opensource contribution in Hacktoberfest contest.

@JLLeitschuh
Copy link
Owner

Hi @rafalh, Thanks for the contribution! Sorry for taking so long to get back to you!

In order to accept this PR, I'd need a test that demonstrates the fix you're making here.

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

2 participants