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

Refactors task's inputs to support configuration cache for modern Gradle versions #235

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

igormukhin
Copy link

@igormukhin igormukhin commented Oct 26, 2024

This PR solves #225.

About the changes:

  1. The task now have inputs that are not calculated dynamically but derived from the user's configuration. The inputs only consider relevant files .git/config, .git/HEAD, .git/refs/**
  2. This dramatically improves the speed by which Gradle can check if the task is still up-to-date
  3. This enables the use of configuration cache in modern Gradle 8.1+ versions

Drawback: This PR also introduces a minor backward incompatibility. The location of the .git directory is not searched up the directory tree automatically anymore. The git directory has to be set explicitly with dotGitDirectory property.

Reasoning:

  • Searching for the repository root directory automatically was probably not the ideal decision in the first place. This makes the Gradle configuration to depend on the project files which should not happen.
  • This searching for git also happend if the task itself was disabled.
  • This searching feature makes the plugin incompatible with configuration cache feature.
  • In Gradle 9.0 the configuration cache feature will be turned on by default, and disabling it will be deprecated.

To assist the user who migrated to the new plugin version, he will see the helpful error message:
No Git repository found. Ensure the gitProperties.dotGitDirectory property points to the correct .git directory.

…radle versions

Breaks backward compatibility: The locations of the .git directory is not searched up the directory tree automatically anymore.
@igormukhin igormukhin changed the title Refactors plugin's inputs to support configuration cache for modern Gradle versions Refactors task's inputs to support configuration cache for modern Gradle versions Oct 26, 2024
@artemptushkin
Copy link

How was it tested? Provide examples please of running the snapshot version with no error and clearly enabled configuration cache

@igormukhin
Copy link
Author

igormukhin commented Oct 28, 2024

I created this project https://github.com/igormukhin/gradle-git-properties-demo to test the changes.

The test can replicated by this:

  • Check out https://github.com/n0mer/gradle-git-properties
  • Switch to PR branch with gh pr checkout 235
  • run ./gradlew publishToMavenLocal
  • Now check out https://github.com/igormukhin/gradle-git-properties-demo

The configuration cache is enabled by default in gradle.properties and the plugin gets picked up from the local Maven repo.

  • Run ./gradlew build
  • You should see that configuration will be produced.
  • Run ./gradlew build again
  • You should see that configuration cache will be reused.
  • Edit some code in Main.java
  • Run ./gradlew build again
  • You should see that configuration cache will be reused but compile tasks run again.
  • Commit the changes with git.
  • Run ./gradlew build again
  • You should see that git.properties will be recreated and build re-run.

Any ideas about how to automate the test are welcome.

@tha2015
Copy link
Collaborator

tha2015 commented Oct 29, 2024

Thank you for your contribution! I’ll need a bit of time to review it thoroughly, as I’d like to refresh myself on some of the implementation details. I’ll get back to you soon!

@igormukhin
Copy link
Author

After (if) the PR gets merged, we can think about upgrading the Gradle version of the project. By that:

  • we can update the BackwardCompatibilityFunctionalTest.java
  • ConfigurationCacheFunctionalTest.java will become more relevant

@artemptushkin
Copy link

@tha2015 I think I see one of the main maintainers here. Sorry for off-top but the project was updated last time in 05.2022 - more than 2 years ago. It's very far from the recent Gradle and I'm pretty sure it might have some issues with recent Gradle versions.

My point is, Spring refers it in the docs, people use it but they do not have updates. Can we clarify the status of the project?

We have a project here that was cloned and changed about a year ago so it supports Gradle CC.

Maybe it's time to refine and switch to the new plugin for Spring references

@tha2015
Copy link
Collaborator

tha2015 commented Oct 30, 2024

@artemptushkin You’re absolutely right; the project hasn’t been actively maintained for a while, and to ensure its long-term sustainability, we’ll likely need new contributors—assuming there’s still interest from the community. Unfortunately, @n0mer hasn’t been active recently, so while I can assist with merging and publishing updates, I don’t currently have access to adjust project settings or facilitate ownership transfer. Moving forward, it’s really up to us as a community to decide if we’d like to keep it going or let it go.

@tha2015
Copy link
Collaborator

tha2015 commented Oct 31, 2024

Hi everyone, please let me know if you'd like me to merge and publish an RC (release candidate) version.

@DevNatan
Copy link

DevNatan commented Nov 5, 2024

Hi everyone, please let me know if you'd like me to merge and publish an RC (release candidate) version.

100%

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.

5 participants