Skip to content

Commit 5d9ec91

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

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

CONTRIBUTING.md

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,47 @@ 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+
just add this to your shell config: ~/.zshrc
106+
export spotlessApply=true
107+
export rewriteRun=true
108+
109+
#### Rewriting
110+
111+
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.
112+
113+
**Usage requirements:**
114+
1. Both `CI` and `rewriteRun` environment variables must be set:
115+
- `CI=false` to enable execution
116+
- `rewriteRun=true` to auto-apply suggestions
117+
2. Dry runs execute by default for change preview
118+
3. Changes are blocked in CI environments (when `CI=true`)
119+
4. Always review changes before applying
91120

92121
#### Documentation
93122

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import org.gradle.plugins.ide.eclipse.model.Classpath
44
import org.gradle.plugins.ide.eclipse.model.Library
55
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
66
import org.gradle.plugins.ide.eclipse.model.SourceFolder
7+
import java.lang.Boolean.valueOf
8+
import java.lang.System.getenv
79

810
plugins {
911
`java-library`
@@ -18,11 +20,15 @@ plugins {
1820

1921
rewrite {
2022
activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17")
23+
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods")
24+
activeRecipe("org.openrewrite.staticanalysis.MissingOverrideAnnotation")
25+
failOnDryRunResults = true
2126
}
2227

2328
dependencies {
2429
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:latest.release"))
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+
assemble {
290+
if (valueOf(getenv("rewriteRun")) && getenv("CI") == null) {
291+
dependsOn("rewriteRun")
292+
}
293+
dependsOn("rewriteDryRun")
294+
}
283295
}
284296

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

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import junitbuild.extensions.requiredVersionFromLibs
2+
import java.lang.Boolean.valueOf
3+
import java.lang.System.getenv
24

35
plugins {
46
id("com.diffplug.spotless")
@@ -86,4 +88,9 @@ tasks {
8688
named("spotlessMisc") {
8789
outputs.doNotCacheIf("negative avoidance savings") { true }
8890
}
91+
if (valueOf(getenv("spotlessApply")) && getenv("CI") == null) {
92+
assemble {
93+
dependsOn("spotlessApply")
94+
}
95+
}
8996
}

0 commit comments

Comments
 (0)