Skip to content

(re)activate rewrite capability #4708

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,47 @@ Whenever an acronym is included as part of a field name or parameter name:

#### Code

Code formatting is enforced using the [Spotless](https://github.com/diffplug/spotless)
Gradle plugin. You can use `gradle spotlessApply` to format new code and add missing
license headers to source files. Formatter and import order settings for Eclipse are
available in the repository under
[junit-eclipse-formatter-settings.xml](gradle/config/eclipse/junit-eclipse-formatter-settings.xml)
and [junit-eclipse.importorder](gradle/config/eclipse/junit-eclipse.importorder),
respectively. For IntelliJ IDEA there's a
[plugin](https://plugins.jetbrains.com/plugin/6546) you can use in conjunction with the
Eclipse settings.

It is forbidden to use _wildcard imports_ (e.g., `import static org.junit.jupiter.api.Assertions.*;`)
in Java code.
Code formatting is automatically enforced using the [Spotless](https://github.com/diffplug/spotless) Gradle plugin during the build process. The build will:

- Automatically format all code
- Add missing license headers
- Correct import order
- Fix other style issues

You can run the plugin goal `gradle spotlessApply` to apply formation.
Nevertheless, that´s not required, as the build handles everything automatically.

IDE configuration is available for consistency:
- **Eclipse**: Use our predefined settings:
- [Formatter config](gradle/config/eclipse/junit-eclipse-formatter-settings.xml)
- [Import order](gradle/config/eclipse/junit-eclipse.importorder)
- **IntelliJ**: Install the [Eclipse Code Formatter plugin](https://plugins.jetbrains.com/plugin/6546) with our settings

**Important**: Wildcard imports (e.g., `import static org.junit.jupiter.api.Assertions.*;`) remain strictly forbidden.

**Usage requirements:**
1. Both `CI` and `rewriteRun` environment variables must be set:
- `CI=false` to enable execution
- `spotlessApply=true` to auto-apply suggestions
2. Dry runs execute by default for change preview
3. Changes are blocked in CI environments (when `CI=true`)
4. Always review changes before applying

just add this to your shell config: ~/.zshrc
export spotlessApply=true
export rewriteRun=true

#### Rewriting

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.

**Usage requirements:**
1. Both `CI` and `rewriteRun` environment variables must be set:
- `CI=false` to enable execution
- `rewriteRun=true` to auto-apply suggestions
2. Dry runs execute by default for change preview
3. Changes are blocked in CI environments (when `CI=true`)
4. Always review changes before applying

#### Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ plugins {

rewrite {
activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17")
activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods")
activeRecipe("org.openrewrite.staticanalysis.MissingOverrideAnnotation")
failOnDryRunResults = true
}

dependencies {
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:latest.release"))
rewrite("org.openrewrite.recipe:rewrite-migrate-java")
rewrite("org.openrewrite.recipe:rewrite-static-analysis")
}

val mavenizedProjects: List<Project> by rootProject.extra
Expand Down Expand Up @@ -280,6 +284,9 @@ tasks {
checkstyleTest {
config = resources.text.fromFile(checkstyle.configDirectory.file("checkstyleTest.xml"))
}
check {
dependsOn("rewriteDryRun")
}
}

pluginManager.withPlugin("java-test-fixtures") {
Expand Down