Skip to content
Merged
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
27 changes: 27 additions & 0 deletions src/main/resources/META-INF/rewrite/java-version-25.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,33 @@ recipeList:
groupId: net.bytebuddy
artifactId: byte-buddy*
newVersion: 1.17.x
# Both distributions bundle an AspectJ too old to read Java 25 bytecode, so aspectjtools is pinned on the plugin.
# dev.aspectj is otherwise interchangeable, but org.codehaus.mojo's `complianceLevel` default of 1.4 is now fatal.
- org.openrewrite.maven.ChangePluginGroupIdAndArtifactId:
oldGroupId: org.codehaus.mojo
oldArtifactId: aspectj-maven-plugin
newGroupId: dev.aspectj
newVersion: 1.14.x
- org.openrewrite.maven.AddPluginDependency:
pluginGroupId: dev.aspectj
pluginArtifactId: aspectj-maven-plugin
groupId: org.aspectj
artifactId: aspectjtools
version: 1.9.25.1
- org.openrewrite.xml.ChangeTagValue:
elementName: //plugin[artifactId='aspectj-maven-plugin']/configuration/complianceLevel
newValue: "25"
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: org.aspectj
artifactId: aspectj*
newVersion: 1.9.x
# mockito-inline was last published as 5.2.0 and inline mocking is the default in mockito-core 5.x, so fold it in
# before the bump below rather than leaving a coordinate that no longer resolves.
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.mockito
oldArtifactId: mockito-inline
newArtifactId: mockito-core
- org.openrewrite.maven.RemoveDuplicateDependencies
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: org.mockito
artifactId: mockito-*
Expand Down
135 changes: 135 additions & 0 deletions src/test/java/org/openrewrite/java/migrate/UpgradeToJava25Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,139 @@ void addsLombokAnnotationProcessor() {
)
);
}

@Test
void mockitoInlineFoldedIntoMockitoCore() {
// mockito-inline was last published as 5.2.0, so bumping a shared mockito version property would otherwise
// leave it unresolvable; inline mocking is the default in mockito-core 5.x.
rewriteRun(
mavenProject("project",
pomXml(
//language=xml
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<maven.compiler.release>17</maven.compiler.release>
<mockito.version>5.2.0</mockito.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""",
spec -> spec.after(actual ->
assertThat(actual)
.contains("<maven.compiler.release>25</maven.compiler.release>")
.doesNotContain("mockito-inline")
.contains("<artifactId>mockito-core</artifactId>")
.containsPattern("<mockito.version>5\\.17\\.")
.actual())
)
)
);
}

@Test
void mockitoInlineAlongsideMockitoCoreLeavesNoDuplicate() {
rewriteRun(
mavenProject("project",
pomXml(
//language=xml
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<maven.compiler.release>17</maven.compiler.release>
<mockito.version>5.2.0</mockito.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""",
spec -> spec.after(actual ->
assertThat(actual)
.doesNotContain("mockito-inline")
.containsOnlyOnce("<artifactId>mockito-core</artifactId>")
.containsPattern("<mockito.version>5\\.17\\.")
.actual())
)
)
);
}

@Test
void upgradesAspectJMavenPluginForJava25() {
// Only AspectJ 1.9.25 and later can read Java 25 bytecode, and neither plugin distribution bundles a compiler
// that new, so aspectjtools is pinned on the plugin itself.
rewriteRun(
mavenProject("project",
pomXml(
//language=xml
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.13</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<complianceLevel>1.8</complianceLevel>
</configuration>
</plugin>
</plugins>
</build>
</project>
""",
spec -> spec.after(actual ->
assertThat(actual)
.contains("<maven.compiler.source>25</maven.compiler.source>")
.doesNotContain("org.codehaus.mojo")
.containsPattern("<groupId>dev.aspectj</groupId>\\s*<artifactId>aspectj-maven-plugin</artifactId>\\s*<version>1\\.14\\.")
.containsPattern("<artifactId>aspectjtools</artifactId>\\s*<version>1\\.9\\.25")
.contains("<complianceLevel>25</complianceLevel>")
.containsPattern("<artifactId>aspectjrt</artifactId>\\s*<version>1\\.9\\.")
.actual())
)
)
);
}
}
Loading