openrewrite / openrewrite/rewrite-migrate-java
Support Spring Boot apps with no explicit version config
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 156
- Forks
- 130
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 21
Description
test case:
@Test
fun `adds java version property if not present if spring-like parent`() = rewriteRun(
pomXml("""
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
</parent>
</project>
""".trimIndent(),
"""
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
</parent>
<properties>
<java.version>11</java.version>
</properties>
</project>
""".trimIndent()
) // fails with no change
)
Spring Boot declares a java.version property, pre-wired into the maven-compiler-plugin config. This is a convenient, common pattern to manage a project's Java version, and our recipes support updating that property if present.
But, because Spring Boot provides a default value (1.8) for java.version, it's feasible for a Spring Boot app to have no explicit configuration for its Java version in its pom.xml. And in that case, the upgrade recipe will do everything but actually update the build's Java version. The test case above shows this.
The tricky part here is deciding how generic the solution should be -- eg:
- do we just check for the "hardcoded" spring-boot-starter-parent parent, or identify arbitrary (non-project) parents which declare
java.version - should we validate that project pom isn't already managing its java version a different way (ie no explicit maven-compiler-plugin config)
- should we enforce an opinion that projects with spring-like parents should only use the
java.versionproperty to manage the Java version
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Kotlin rewriteRun test in the issue and inspect the existing recipes that update the java.version property. Determine how Spring Boot parent defaults should be handled alongside other Java-version configuration, then add coverage for the chosen behavior. Done means the provided test passes without breaking existing migration cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin, spring-boot
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100