Skip to content

Commit aba289d

Browse files
author
Vincent Potucek
committed
activate unused rewrite checks failOnDryRunResults
1 parent 942a2f8 commit aba289d

File tree

3 files changed

+55
-13
lines changed

3 files changed

+55
-13
lines changed

CONTRIBUTING.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,43 @@ Whenever an acronym is included as part of a field name or parameter name:
7676

7777
#### Code
7878

79-
Code formatting is enforced using the [Spotless](https://github.com/diffplug/spotless)
80-
Gradle plugin. You can use `gradle spotlessApply` to format new code and add missing
81-
license headers to source files. Formatter and import order settings for Eclipse are
82-
available in the repository under
83-
[junit-eclipse-formatter-settings.xml](gradle/config/eclipse/junit-eclipse-formatter-settings.xml)
84-
and [junit-eclipse.importorder](gradle/config/eclipse/junit-eclipse.importorder),
85-
respectively. For IntelliJ IDEA there's a
86-
[plugin](https://plugins.jetbrains.com/plugin/6546) you can use in conjunction with the
87-
Eclipse settings.
88-
89-
It is forbidden to use _wildcard imports_ (e.g., `import static org.junit.jupiter.api.Assertions.*;`)
90-
in Java code.
79+
Code formatting is automatically enforced using the [Spotless](https://github.com/diffplug/spotless) Gradle plugin during the build process. The build will:
80+
81+
- Automatically format all code
82+
- Add missing license headers
83+
- Correct import order
84+
- Fix other style issues
85+
86+
You can run the plugin goal `gradle spotlessApply` to apply formation.
87+
Nevertheless, that´s not required, as the build handles everything automatically.
88+
89+
IDE configuration is available for consistency:
90+
- **Eclipse**: Use our predefined settings:
91+
- [Formatter config](gradle/config/eclipse/junit-eclipse-formatter-settings.xml)
92+
- [Import order](gradle/config/eclipse/junit-eclipse.importorder)
93+
- **IntelliJ**: Install the [Eclipse Code Formatter plugin](https://plugins.jetbrains.com/plugin/6546) with our settings
94+
95+
**Important**: Wildcard imports (e.g., `import static org.junit.jupiter.api.Assertions.*;`) remain strictly forbidden.
96+
97+
**Usage requirements:**
98+
1. Both `CI` and `rewriteRun` environment variables must be set:
99+
- `CI=false` to enable execution
100+
- `spotlessApply=true` to auto-apply suggestions
101+
2. Dry runs execute by default for change preview
102+
3. Changes are blocked in CI environments (when `CI=true`)
103+
4. Always review changes before applying
104+
105+
#### Rewriting
106+
107+
The build supports automated code refactoring through [Moderne](https://moderne.io/) rewrite rules. These transformations are controlled exclusively through environment variables - there is no local variable configuration option to apply automatic fixes out of the box.
108+
109+
**Usage requirements:**
110+
1. Both `CI` and `rewriteRun` environment variables must be set:
111+
- `CI=false` to enable execution
112+
- `rewriteRun=true` to auto-apply suggestions
113+
2. Dry runs execute by default for change preview
114+
3. Changes are blocked in CI environments (when `CI=true`)
115+
4. Always review changes before applying
91116

92117
#### Documentation
93118

gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ plugins {
1818

1919
rewrite {
2020
activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17")
21+
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods")
22+
activeRecipe("org.openrewrite.staticanalysis.MissingOverrideAnnotation")
23+
failOnDryRunResults = true
2124
}
2225

2326
dependencies {
24-
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:latest.release"))
27+
// https://github.com/openrewrite/rewrite/issues/5677
28+
// rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:latest.release"))
29+
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.10.0"))
2530
rewrite("org.openrewrite.recipe:rewrite-migrate-java")
31+
rewrite("org.openrewrite.recipe:rewrite-static-analysis")
2632
}
2733

2834
val mavenizedProjects: List<Project> by rootProject.extra
@@ -280,6 +286,12 @@ tasks {
280286
checkstyleTest {
281287
config = resources.text.fromFile(checkstyle.configDirectory.file("checkstyleTest.xml"))
282288
}
289+
check {
290+
dependsOn("rewriteDryRun")
291+
if (System.getenv("rewriteRun") != null && System.getenv("CI") == null) {
292+
dependsOn("rewriteRun")
293+
}
294+
}
283295
}
284296

285297
pluginManager.withPlugin("java-test-fixtures") {

gradle/plugins/common/src/main/kotlin/junitbuild.spotless-conventions.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,9 @@ tasks {
8686
named("spotlessMisc") {
8787
outputs.doNotCacheIf("negative avoidance savings") { true }
8888
}
89+
if (System.getenv("spotlessApply") != null && System.getenv("CI") == null) {
90+
check {
91+
dependsOn("spotlessApply")
92+
}
93+
}
8994
}

0 commit comments

Comments
 (0)