openrewrite / openrewrite/rewrite
Replace `tasks.withType<...> { ... }` with `tasks.withType<...>().configureEach { ... }` to support Gradle configuration avoidance
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
What problem are you trying to solve?
tasks.withType<...> {...} does not support configuration avoidance, and it is almost always should be replaced with tasks.withType<...>().configureEach {...}
The same could be done for Groovy DSL.
What precondition(s) should be checked before applying this recipe?
Gradle should be 4.9+
Describe the situation before applying the recipe
tasks.withType<Javadoc> {
// generated ANTLR sources violate doclint
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
// Items besides JavaParser due to lombok error which looks similar to this:
// openrewrite/rewrite/rewrite-java/src/main/java/org/openrewrite/java/OrderImports.java:42: error: cannot find symbol
// @AllArgsConstructor(onConstructor_=@JsonCreator)
// ^
// symbol: method onConstructor_()
// location: @interface AllArgsConstructor
// 1 error
exclude("**/JavaParser**", "**/ChangeMethodTargetToStatic**", "**/J.java")
}
Describe the situation after applying the recipe
tasks.withType<Javadoc>().configureEach {
// generated ANTLR sources violate doclint
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
// Items besides JavaParser due to lombok error which looks similar to this:
// openrewrite/rewrite/rewrite-java/src/main/java/org/openrewrite/java/OrderImports.java:42: error: cannot find symbol
// @AllArgsConstructor(onConstructor_=@JsonCreator)
// ^
// symbol: method onConstructor_()
// location: @interface AllArgsConstructor
// 1 error
exclude("**/JavaParser**", "**/ChangeMethodTargetToStatic**", "**/J.java")
}
Any additional context
See https://youtrack.jetbrains.com/issue/IDEA-297893/Inspection-for-tasks.all-tasks.withType...-...-prefer-lazy-task-configuration-configuration-avoidance
See https://github.com/openrewrite/rewrite/blob/efd3214f6f3317a8a59d64821f30211ac6d9993e/rewrite-java/build.gradle.kts#L61-L73
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with rewrite-java/build.gradle.kts#L61-L73 and the linked Gradle task-configuration-avoidance guide. Search the repository for Kotlin and Groovy tasks.withType usages, check the Gradle 4.9 precondition, and verify that matching blocks use configureEach without changing their contents.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- build-system
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100