-
Notifications
You must be signed in to change notification settings - Fork 160
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ import org.junit.jupiter.api.DisplayName | |
@GradleTestVersions | ||
class ConfigurationCacheTest : AbstractPluginTest() { | ||
private val configurationCacheFlag = "--configuration-cache" | ||
private val configurationCacheWarnFlag = "--configuration-cache-problems=warn" | ||
|
||
@DisplayName("Should support configuration cache without errors on running linting") | ||
@CommonTest | ||
|
@@ -29,15 +28,13 @@ class ConfigurationCacheTest : AbstractPluginTest() { | |
|
||
build( | ||
configurationCacheFlag, | ||
configurationCacheWarnFlag, | ||
CHECK_PARENT_TASK_NAME | ||
) { | ||
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
} | ||
|
||
build( | ||
configurationCacheFlag, | ||
configurationCacheWarnFlag, | ||
CHECK_PARENT_TASK_NAME | ||
) { | ||
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) | ||
|
@@ -58,15 +55,13 @@ class ConfigurationCacheTest : AbstractPluginTest() { | |
val formatTaskName = KtLintFormatTask.buildTaskNameForSourceSet("main") | ||
build( | ||
configurationCacheFlag, | ||
configurationCacheWarnFlag, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate on why this isn't needed anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
So we probably want this test to fail in the future if someone implements something that is not capable of configuration caching? |
||
FORMAT_PARENT_TASK_NAME | ||
) { | ||
assertThat(task(":$formatTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
assertThat(task(":$mainSourceSetFormatTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
} | ||
build( | ||
configurationCacheFlag, | ||
configurationCacheWarnFlag, | ||
FORMAT_PARENT_TASK_NAME, | ||
"--debug" | ||
) { | ||
|
@@ -77,6 +72,50 @@ class ConfigurationCacheTest : AbstractPluginTest() { | |
} | ||
} | ||
|
||
@DisplayName("Should support configuration cache on running format tasks with relative paths") | ||
@CommonTest | ||
fun configurationCacheForFormatTasksWithRelativePaths(gradleVersion: GradleVersion) { | ||
project(gradleVersion) { | ||
buildGradle.appendText( | ||
//language=Groovy | ||
""" | ||
repositories { | ||
jcenter() | ||
} | ||
|
||
ktlint { | ||
relative = true | ||
reporters { | ||
reporter "plain" | ||
reporter "checkstyle" | ||
} | ||
} | ||
""".trimIndent() | ||
) | ||
val sourceFile = "\nval foo = \"bar\"\n" | ||
createSourceFile( | ||
"src/main/kotlin/CleanSource.kt", | ||
sourceFile | ||
) | ||
val formatTaskName = KtLintFormatTask.buildTaskNameForSourceSet("main") | ||
build( | ||
configurationCacheFlag, | ||
FORMAT_PARENT_TASK_NAME | ||
) { | ||
assertThat(task(":$formatTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
assertThat(task(":$mainSourceSetFormatTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
} | ||
build( | ||
configurationCacheFlag, | ||
FORMAT_PARENT_TASK_NAME | ||
) { | ||
assertThat(task(":$formatTaskName")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) | ||
assertThat(task(":$mainSourceSetFormatTaskName")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) | ||
assertThat(output).contains("Reusing configuration cache.") | ||
} | ||
} | ||
} | ||
|
||
@DisplayName("Should support configuration cache for git hook format install task") | ||
@CommonTest | ||
internal fun configurationCacheForGitHookFormatInstallTask(gradleVersion: GradleVersion) { | ||
|
@@ -85,15 +124,13 @@ class ConfigurationCacheTest : AbstractPluginTest() { | |
|
||
build( | ||
configurationCacheFlag, | ||
configurationCacheWarnFlag, | ||
INSTALL_GIT_HOOK_FORMAT_TASK | ||
) { | ||
assertThat(task(":$INSTALL_GIT_HOOK_FORMAT_TASK")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
} | ||
|
||
build( | ||
configurationCacheFlag, | ||
configurationCacheWarnFlag, | ||
INSTALL_GIT_HOOK_FORMAT_TASK | ||
) { | ||
assertThat(task(":$INSTALL_GIT_HOOK_FORMAT_TASK")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
|
@@ -110,15 +147,13 @@ class ConfigurationCacheTest : AbstractPluginTest() { | |
|
||
build( | ||
configurationCacheFlag, | ||
configurationCacheWarnFlag, | ||
INSTALL_GIT_HOOK_CHECK_TASK | ||
) { | ||
assertThat(task(":$INSTALL_GIT_HOOK_CHECK_TASK")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
} | ||
|
||
build( | ||
configurationCacheFlag, | ||
configurationCacheWarnFlag, | ||
INSTALL_GIT_HOOK_CHECK_TASK | ||
) { | ||
assertThat(task(":$INSTALL_GIT_HOOK_CHECK_TASK")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
|
There was a problem hiding this comment.
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? 🙂There was a problem hiding this comment.
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
or do I misunderstand you?
There was a problem hiding this comment.
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 theinit
block, but re-reading the code, I was completely wrong. My mistake.Thanks for adding a comment inline in the code! 🙂