Skip to content

Commit 258b99b

Browse files
authored
Upgrade Scala dependencies as part of Java 11 upgrade (#529)
1 parent 83572ca commit 258b99b

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

src/main/resources/META-INF/rewrite/java-version-11.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ recipeList:
7272
- org.openrewrite.java.migrate.ReplaceAWTGetPeerMethod:
7373
getPeerMethodPattern: java.awt.* getPeer()
7474
lightweightPeerFQCN: java.awt.peer.LightweightPeer
75+
- org.openrewrite.scala.migrate.UpgradeScala_2_12
7576
---
7677
type: specs.openrewrite.org/v1beta/recipe
7778
name: org.openrewrite.java.migrate.UpgradeBuildToJava11
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright 2024 the original author or authors.
3+
# <p>
4+
# Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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+
# As per: https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html
18+
---
19+
type: specs.openrewrite.org/v1beta/recipe
20+
name: org.openrewrite.scala.migrate.UpgradeScala_2_12
21+
displayName: Migrate to Scala 2.12.+
22+
description: >-
23+
Upgrade the Scala version for compatibility with newer Java versions.
24+
tags:
25+
- scala
26+
recipeList:
27+
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
28+
groupId: org.scala-lang
29+
artifactId: scala-*
30+
newVersion: 2.12.x
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.test.RecipeSpec;
21+
import org.openrewrite.test.RewriteTest;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
import static org.openrewrite.maven.Assertions.pomXml;
25+
26+
class UpgradeScalaTest implements RewriteTest {
27+
28+
@Override
29+
public void defaults(RecipeSpec spec) {
30+
spec.recipeFromResource(
31+
"/META-INF/rewrite/scala.yml",
32+
"org.openrewrite.scala.migrate.UpgradeScala_2_12");
33+
}
34+
35+
@DocumentExample
36+
@Test
37+
void upgradeScalaDependencies() {
38+
rewriteRun(
39+
pomXml(
40+
//language=xml
41+
"""
42+
<project>
43+
<modelVersion>4.0.0</modelVersion>
44+
<groupId>com.mycompany.app</groupId>
45+
<artifactId>my-app</artifactId>
46+
<version>1</version>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.scala-lang</groupId>
50+
<artifactId>scala-library</artifactId>
51+
<version>2.12.0</version>
52+
</dependency>
53+
</dependencies>
54+
</project>
55+
""",
56+
after -> after.after(str -> str).afterRecipe(
57+
doc -> assertThat(doc.getRoot()
58+
.getChild("dependencies").get()
59+
.getChild("dependency").get()
60+
.getChildValue("version").get())
61+
.matches("2.12.[1-9]\\d"))
62+
)
63+
);
64+
}
65+
}

0 commit comments

Comments
 (0)