OpenRewrite recipe development and test maintenance. Use when writing OpenRewrite recipes, fixing test failures, or working with import ordering in recipe tests.
View on GitHubmotlin/claude-code-plugins
java
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/motlin/claude-code-plugins/blob/main/plugins/java/skills/openrewrite/SKILL.md -a claude-code --skill openrewriteInstallation paths:
.claude/skills/openrewrite/# OpenRewrite Recipe Development
This skill provides guidelines for developing OpenRewrite recipes and maintaining their tests, with a focus on import ordering issues.
## Fixing Import Ordering Test Failures
š§ OpenRewrite recipe tests often fail due to import order differences, not actual transformation issues.
### Problem
OpenRewrite recipe tests fail with diffs showing only import order differences:
```diff
-import java.util.List;
-import org.assertj.core.api.Assertions;
+import org.assertj.core.api.Assertions;
+import java.util.List;
```
### Root Cause
OpenRewrite manages imports automatically based on:
- Existing imports in the file
- JavaTemplate configuration
- Import optimization rules
- The order may differ from test expectations
### Solution Approach
#### 1. Fix the Recipe (if imports are missing)
Ensure your JavaTemplate is properly configured:
```java
JavaTemplate template = JavaTemplate
.builder("Your.template.code()")
.imports(
"org.assertj.core.api.Assertions",
"org.eclipse.collections.impl.utility.Iterate"
)
.contextSensitive() // Important for proper context handling
.javaParser(JavaParser.fromJavaVersion()
.classpath("assertj-core", "eclipse-collections", "eclipse-collections-api")
)
.build();
```
Don't forget to call:
```java
maybeAddImport("org.assertj.core.api.Assertions");
maybeAddImport("org.eclipse.collections.impl.utility.Iterate");
maybeRemoveImport("old.package.OldClass");
```
#### 2. Fix the Test Expectations
Accept the actual import order that OpenRewrite produces:
ā Instead of forcing a specific order:
```java
// DON'T expect a specific order you want
"import java.util.List;\n" +
"import org.assertj.core.api.Assertions;\n"
```
ā
Use the actual order OpenRewrite produces:
```java
// DO accept the order OpenRewrite generates
"import org.assertj.core.api.Assertions;\n" +
"import org.eclipse.collections.impl.utility.Iterate;\n" +
"\n" +
"import java.util.List;\n"
```