OpenRewrite recipe best practices
Recipe ID
org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPracticesArtifactorg.openrewrite.recipe:rewrite-rewriteBest practices for OpenRewrite recipe development.
Composite recipeMSAL
Add to your build
Get a download tokenThis recipe is Moderne licensed, so the token must belong to a Moderne customer. It replaces YOUR_DOWNLOAD_TOKEN below.
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPractices")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-rewrite:0.33.0")
}
Then run
./gradlew rewriteRunUsage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPracticesIf the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-rewrite:RELEASEDefinition
This recipe runs the following recipes in order.
- Set the Develocity
serverhttps://community.develocity.cloud/org.openrewrite.gradle.plugins.SetDevelocityServer - Set the Develocity
projectIdopenrewriteorg.openrewrite.gradle.plugins.SetDevelocityProjectId - Inline calls to deprecated OpenRewrite methods
org.openrewrite.recipes.rewrite.InlineMethods - Generate
InlineMethodCallsrecipes for deprecated delegating methodsorg.openrewrite.java.recipes.GenerateDeprecatedMethodRecipes - Java Recipe best practices
org.openrewrite.java.recipes.JavaRecipeBestPractices - Recipe testing best practices
org.openrewrite.java.recipes.RecipeTestingBestPractices - Recipe nullability best practices
org.openrewrite.java.recipes.RecipeNullabilityBestPractices - Remove elements annotated with
@ToBeRemovedpast their dateorg.openrewrite.java.recipes.RemoveToBeRemoved - Migrate tests to Java 21
org.openrewrite.java.recipes.UpgradeTestsToJava21 - Extract documentation examples from tests
org.openrewrite.java.recipes.ExamplesExtractor - Order imports
org.openrewrite.java.OrderImports - Remove unused imports
org.openrewrite.java.RemoveUnusedImports - Simplify single-element annotation
org.openrewrite.java.SimplifySingleElementAnnotation - End files with a single newline
org.openrewrite.java.format.EmptyNewlineAtEndOfFile - Remove trailing whitespace
org.openrewrite.java.format.RemoveTrailingWhitespace - Inline variable
org.openrewrite.staticanalysis.InlineVariable - Operator wrapping
org.openrewrite.staticanalysis.OperatorWrap - Remove unused local variables
org.openrewrite.staticanalysis.RemoveUnusedLocalVariables - Remove unused private fields
org.openrewrite.staticanalysis.RemoveUnusedPrivateFields - Remove unused private methods
org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods - Unwrap else block after return or throw statement
org.openrewrite.staticanalysis.UnwrapElseAfterReturn - Equals avoids null
org.openrewrite.staticanalysis.EqualsAvoidsNull - Add missing
@Overrideto overriding and implementing methodsorg.openrewrite.staticanalysis.MissingOverrideAnnotation - Week Year (YYYY) should not be used for date formatting
org.openrewrite.staticanalysis.ReplaceWeekYearWithYear hashCode()should not be called on array instancesorg.openrewrite.staticanalysis.RemoveHashCodeCallsFromArrayInstances- Remove
toString()calls on arraysorg.openrewrite.staticanalysis.RemoveToStringCallsFromArrayInstances - Replaces
Object.notify()withObject.notifyAll()org.openrewrite.staticanalysis.UseObjectNotifyAll - Remove garbage collection invocations
org.openrewrite.staticanalysis.RemoveCallsToSystemGc - Remove
Object.finalize()invocationsorg.openrewrite.staticanalysis.RemoveCallsToObjectFinalize - URL Equals and Hash Code
org.openrewrite.staticanalysis.URLEqualsHashCodeRecipes - Simplify lambda blocks to expressions
org.openrewrite.staticanalysis.LambdaBlockToExpression - Use method references in lambda
org.openrewrite.staticanalysis.ReplaceLambdaWithMethodReference - Use the diamond operator
org.openrewrite.staticanalysis.UseDiamondOperator - Remove unnecessary parentheses
org.openrewrite.staticanalysis.UnnecessaryParentheses - Remove redundant null checks before instanceof
org.openrewrite.staticanalysis.RemoveRedundantNullCheckBeforeInstanceof - Replace
StringBuilder#appendwithStringorg.openrewrite.staticanalysis.ReplaceStringBuilderWithString - Use
Collectioninterfacesorg.openrewrite.staticanalysis.UseCollectionInterfaces - Enum values should be compared with "=="
org.openrewrite.staticanalysis.CompareEnumsWithEqualityOperator - Combine semantically equal catch blocks
org.openrewrite.staticanalysis.CombineSemanticallyEqualCatchBlocks - Use
String::replace()when first parameter is not a real regular expressionorg.openrewrite.staticanalysis.UseStringReplace - Use
StandardCharsetconstantsorg.openrewrite.staticanalysis.UseStandardCharset - Use
System.lineSeparator()org.openrewrite.staticanalysis.UseSystemLineSeparator - Remove redundant casts
org.openrewrite.staticanalysis.RemoveRedundantTypeCast - Replace
java.util.Stackwithjava.util.Dequeorg.openrewrite.staticanalysis.ReplaceStackWithDeque - Replace invocations of
Collections#sort(List, Comparator)withList#sort(Comparator)org.openrewrite.staticanalysis.UseListSort - Use
String.contentEquals(CharSequence)instead ofString.equals(CharSequence.toString())org.openrewrite.staticanalysis.EqualsToContentEquals - Use static import
java.util.stream.Collectors *(..)org.openrewrite.java.UseStaticImport - Use static import
java.util.Collections *(..)org.openrewrite.java.UseStaticImport
Data tables
Structured output this recipe can produce.
- Deprecated method delegationsDeprecated methods that delegate to another method in the same class, suitable for inlining via `InlineMethodCalls`.
org.openrewrite.java.recipes.DeprecatedMethodDelegations - Maven metadata failuresAttempts to resolve maven metadata that failed.
org.openrewrite.maven.table.MavenMetadataFailures - Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats