Skip to content

Commit 297bd55

Browse files
Adding declarative recipe for migrating com.intellij:annotations dependencies to org.jetbrains:annotations. As noted in the issue, the packages used within the dependencies were already using org.jetbrains.annotations back to the oldest available version of com.intelli:annotations so packages do not need to be migrated.
1 parent 244dc5c commit 297bd55

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Copyright 2025 the original author or authors.
3+
# <p>
4+
# Licensed under the Moderne Source Available License (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# <p>
8+
# https://docs.moderne.io/licensing/moderne-source-available-license
9+
# <p>
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
---
18+
type: specs.openrewrite.org/v1beta/recipe
19+
name: org.openrewrite.java.migrate.ComIntelliJAnnotationsToOrgJetbrainsAnnotations
20+
displayName: "Migrate com.intellij:annotations to org.jetbrains:annotations"
21+
description: >-
22+
This recipe will upgrade old dependency of com.intellij:annotations to the newer org.jetbrains:annotations.
23+
tags:
24+
- intellij
25+
- jetbrains
26+
- annotations
27+
recipeList:
28+
- org.openrewrite.java.dependencies.ChangeDependency:
29+
oldGroupId: com.intellij
30+
oldArtifactId: annotations
31+
newGroupId: org.jetbrains
32+
newVersion: latest.release
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
* <p>
4+
* Licensed under the Moderne Source Available License (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://docs.moderne.io/licensing/moderne-source-available-license
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.migrate;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.maven.tree.MavenResolutionResult;
21+
import org.openrewrite.maven.tree.Scope;
22+
import org.openrewrite.test.RecipeSpec;
23+
import org.openrewrite.test.RewriteTest;
24+
25+
import java.util.regex.Matcher;
26+
import java.util.regex.Pattern;
27+
28+
import static java.util.function.UnaryOperator.identity;
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
import static org.openrewrite.gradle.Assertions.buildGradle;
31+
import static org.openrewrite.java.Assertions.mavenProject;
32+
import static org.openrewrite.maven.Assertions.pomXml;
33+
import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi;
34+
35+
public class ComIntelliJAnnotationsToOrgJetbrainsAnnotationsTest implements RewriteTest {
36+
@Override
37+
public void defaults(RecipeSpec spec) {
38+
spec.beforeRecipe(withToolingApi());
39+
spec.recipeFromResource(
40+
"/META-INF/rewrite/intellij-annotations-to-jetbrains-annotations.yml",
41+
"org.openrewrite.java.migrate.ComIntelliJAnnotationsToOrgJetbrainsAnnotations"
42+
);
43+
}
44+
45+
@DocumentExample
46+
@Test
47+
void mavenDependencyUpdate() {
48+
rewriteRun(
49+
mavenProject("project",
50+
pomXml(
51+
//language=xml
52+
"""
53+
<project>
54+
<modelVersion>4.0.0</modelVersion>
55+
56+
<groupId>com.mycompany.app</groupId>
57+
<artifactId>my-app</artifactId>
58+
<version>1</version>
59+
60+
<dependencies>
61+
<dependency>
62+
<groupId>com.intellij</groupId>
63+
<artifactId>annotations</artifactId>
64+
<version>5.1</version>
65+
</dependency>
66+
</dependencies>
67+
</project>
68+
""",
69+
spec -> spec
70+
.after(identity())
71+
.afterRecipe(doc -> assertThat(doc.getMarkers().findFirst(MavenResolutionResult.class)
72+
.get().getDependencies().get(Scope.Compile))
73+
.filteredOn(rd -> rd.getDepth() == 0)
74+
.satisfiesExactly(
75+
rd -> {
76+
assertThat(rd.getGroupId()).isEqualTo("org.jetbrains");
77+
assertThat(rd.getArtifactId()).isEqualTo("annotations");
78+
}))
79+
)
80+
)
81+
);
82+
}
83+
84+
@DocumentExample
85+
@Test
86+
void gradleDependencyUpdates() {
87+
rewriteRun(
88+
buildGradle(
89+
//language=groovy
90+
"""
91+
plugins {
92+
id("java-library")
93+
}
94+
repositories {
95+
mavenCentral()
96+
}
97+
dependencies {
98+
implementation("com.intellij:annotations:5.1")
99+
implementation "com.intellij:annotations:6.0.3"
100+
implementation group: "com.intellij", name: "annotations", version: "12.0"
101+
}
102+
""",
103+
spec -> spec.after(buildGradle -> {
104+
Matcher version = Pattern.compile("\\d+\\.\\d+(\\.\\d+)?").matcher(buildGradle);
105+
assertThat(version.find()).isTrue();
106+
String dependencyVersion = version.group(0);
107+
return """
108+
plugins {
109+
id("java-library")
110+
}
111+
repositories {
112+
mavenCentral()
113+
}
114+
dependencies {
115+
implementation("org.jetbrains:annotations:%1$s")
116+
implementation "org.jetbrains:annotations:%1$s"
117+
implementation group: "org.jetbrains", name: "annotations", version: "%1$s"
118+
}
119+
""".formatted(dependencyVersion);
120+
})
121+
)
122+
);
123+
}
124+
}

0 commit comments

Comments
 (0)