Back to Skills

openrewrite

verified

OpenRewrite recipe development and test maintenance. Use when writing OpenRewrite recipes, fixing test failures, or working with import ordering in recipe tests.

View on GitHub

Marketplace

motlin-claude-code-plugins

motlin/claude-code-plugins

Plugin

java

productivity

Repository

motlin/claude-code-plugins
3stars

plugins/java/skills/openrewrite/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/motlin/claude-code-plugins/blob/main/plugins/java/skills/openrewrite/SKILL.md -a claude-code --skill openrewrite

Installation paths:

Claude
.claude/skills/openrewrite/
Powered by add-skill CLI

Instructions

# 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"
```

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
3564 chars