-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maven - UpdateMavenModel incompatible with CI-Friendly Versions #2049
Comments
Debugging: I believe the issue is in the condition at ~ I'm looking into a fix; need to decide how robust we need to be with validating the |
…I-friendly versions (openrewrite#2049)
@nmck257 I have some time to dig into this. I suspect we just missing a |
@tkvangorder cool -- yeah, if there's a more root-cause fix than my PR (#2050), then by all means. |
Should be closed with 86f9f63 |
I'm seeing issues with this again, albeit different exceptions. My previous PRs seem to have not 100% covered it. @Test
fun `can connect project poms when using CI-friendly version properties`() = 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.sample</groupId>
<artifactId>sample</artifactId>
<version>${'$'}{revision}</version>
<packaging>pom</packaging>
<modules>
<module>sample-parent</module>
<module>sample-app</module>
<module>sample-rest</module>
<module>sample-web</module>
</modules>
<properties>
<revision>0.0.0-SNAPSHOT</revision>
</properties>
</project>
""".trimIndent()) { spec -> spec.path("pom.xml") },
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>sample-parent</artifactId>
<groupId>net.sample</groupId>
<version>${'$'}{revision}</version>
<packaging>pom</packaging>
<properties>
<revision>0.0.0-SNAPSHOT</revision>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.sample</groupId>
<artifactId>sample-web</artifactId>
<version>${'$'}{project.version}</version>
</dependency>
<dependency>
<groupId>net.sample</groupId>
<artifactId>sample-rest</artifactId>
<version>${'$'}{project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
""".trimIndent()) { spec -> spec.path("parent/pom.xml") },
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>sample-app</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>net.sample</groupId>
<artifactId>sample-parent</artifactId>
<version>${'$'}{revision}</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>net.sample</groupId>
<artifactId>sample-rest</artifactId>
</dependency>
<dependency>
<groupId>net.sample</groupId>
<artifactId>sample-web</artifactId>
</dependency>
</dependencies>
</project>
""".trimIndent()) { spec -> spec.path("app/pom.xml") },
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>sample-rest</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>net.sample</groupId>
<artifactId>sample-parent</artifactId>
<version>${'$'}{revision}</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
</project>
""".trimIndent()) { spec -> spec.path("rest/pom.xml") },
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>sample-web</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>net.sample</groupId>
<artifactId>sample-parent</artifactId>
<version>${'$'}{revision}</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
</project>
""".trimIndent()) { spec -> spec.path("web/pom.xml") },
) ...yields:
Debugging, the download request comes during resolution of the The version check (L389) continues to be thorny... in this case, in the relevant iteration, the left side is rewrite/rewrite-maven/src/main/java/org/openrewrite/maven/internal/MavenPomDownloader.java Lines 384 to 392 in 175a358
A naive solution could be removing this version check. A more intricate solution could be refactoring this method (and MavenParser::parseInputs) such that we use module interdependencies to inform project pom resolution order and make the resolved-thus-far project poms available to the |
cc @jkschneider I've drafted changes to resolve the project poms in interdependency-order. And, I've started changing the MavenPomDownloader to use Relevant lines which misbehave if the rewrite/rewrite-maven/src/main/java/org/openrewrite/maven/internal/MavenPomDownloader.java Lines 394 to 410 in 175a358
This issue pushes us towards providing the Or -- noting that Maven does not allow arbitrary properties in the version field, only the CI-friendly version properties I'm leaning towards that last approach. And, with that in place, I don't actually see a clear benefit to resolving the project poms in interdependency-order, but if you're interested in that code, I could open a separate PR for further evaluation. |
Consider running OpenRewrite on a multi-module project, using the
${revision}
pattern described here: https://maven.apache.org/maven-ci-friendly.htmlIf using recipes which trigger
UpdateMavenModel
, then you'll receive log output like this:Overall recipe execution continues, but the maven model updates are cut off by the exception, impacting recipe correctness.
The text was updated successfully, but these errors were encountered: