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

Fix configuration cache for relative paths #722

Merged
merged 2 commits into from Nov 6, 2023
Merged

Fix configuration cache for relative paths #722

merged 2 commits into from Nov 6, 2023

Conversation

rschattauer
Copy link
Contributor

resolves #721

The new test would fail before the changes to generate reports task and succeed afterwards

@JLLeitschuh JLLeitschuh self-requested a review November 2, 2023 13:39
Copy link
Owner

@JLLeitschuh JLLeitschuh left a comment

Choose a reason for hiding this comment

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

Just a few bits of feedback and some questions. Other than that, nice work!

@@ -58,15 +59,13 @@ class ConfigurationCacheTest : AbstractPluginTest() {
val formatTaskName = KtLintFormatTask.buildTaskNameForSourceSet("main")
build(
configurationCacheFlag,
configurationCacheWarnFlag,
Copy link
Owner

Choose a reason for hiding this comment

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

Can you elaborate on why this isn't needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it everywhere in this test now. Reason being that this would not fail the test when configuration actually fails. With relative path you would get a message that reads something like

FAILURE: Build failed with an exception.

* What went wrong:
Configuration cache problems found in this build.

2 problems were found storing the configuration cache, 1 of which seems unique.

So we probably want this test to fail in the future if someone implements something that is not capable of configuration caching?

@@ -90,6 +90,8 @@ abstract class GenerateReportsTask @Inject constructor(
@get:Optional
internal abstract val baseline: RegularFileProperty

private val rootDir: File = project.rootDir
Copy link
Owner

Choose a reason for hiding this comment

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

Does this need to be class scoped? Or can it be scoped smaller, to only the init block? Also, can you elaborate on why this fixes this, or, at minimum, can you include an explicit comment in the code explaining why this is extracted to a variable eagerly. That way the rationale for this change isn't lost in the future? 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:requirements:~:text=Use%3A-,project.rootDir,-A%20task%20input for configuration caching rootDir you should use
A task input or output property or a script variable to capture the result of using project.rootDir to calculate the actual parameter.
So according to https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution A task must not use any Project objects at execution time. This includes calling Task.getProject() while the task is running. and to achieve that I was calling it within the class. I could also let the input set the relative rootdir path, but I thought this is easier to grasp? I added a comment to hopefully make it understandable.

What do you mean with init block scoped? There is no difference to this and

private val rootDir: File
init {
     rootDir = project.rootDir
}

or do I misunderstand you?

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry, I misunderstood the code. I thought the rootDir was only used inside of the init block, but re-reading the code, I was completely wrong. My mistake.

Thanks for adding a comment inline in the code! 🙂

Copy link
Owner

@JLLeitschuh JLLeitschuh left a comment

Choose a reason for hiding this comment

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

LGTM!

@JLLeitschuh
Copy link
Owner

Please add a changelog entry for this change. Then this should be good to go

@rschattauer
Copy link
Contributor Author

Added a line to the changelog @JLLeitschuh

Copy link
Owner

@JLLeitschuh JLLeitschuh left a comment

Choose a reason for hiding this comment

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

LGTM! Now to wait for CI

@rschattauer
Copy link
Contributor Author

@JLLeitschuh , I don't have to click/do anything to continue, correct?

@JLLeitschuh JLLeitschuh merged commit 0f75ad1 into JLLeitschuh:main Nov 6, 2023
14 checks passed
@JLLeitschuh
Copy link
Owner

Merged! Thanks for the fix!!

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.

Configuration cache broken with relative set to true
2 participants