Skip to content

Commit

Permalink
Fixed maven multi module property version problem (#4335)
Browse files Browse the repository at this point in the history
* A property resolver has been added to the normal project version, not just the parent version.

* Added test for the property resolver of the project version

* Apply suggestions from code review

---------

Co-authored-by: marcel-gepardec <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
3 people authored Jul 17, 2024
1 parent f66b109 commit 21183c7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public Stream<SourceFile> parseInputs(Iterable<Input> sources, @Nullable Path re
if (parent != null &&
resolutionResult.getPom().getGroupId().equals(resolutionResult.getPom().getValue(parent.getGroupId())) &&
resolutionResult.getPom().getArtifactId().equals(resolutionResult.getPom().getValue(parent.getArtifactId())) &&
resolutionResult.getPom().getVersion().equals(resolutionResult.getPom().getValue(parent.getVersion()))) {
Objects.equals(resolutionResult.getPom().getValue(resolutionResult.getPom().getVersion()), resolutionResult.getPom().getValue(parent.getVersion()))) {
moduleResolutionResult.unsafeSetParent(resolutionResult);
modules.add(moduleResolutionResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3157,4 +3157,49 @@ void circularMavenProperty() {
)
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/4319")
void multiModulePropertyVersionShouldAddModules() {
rewriteRun(
mavenProject("root",
pomXml(
"""
<project>
<groupId>example</groupId>
<artifactId>example-root</artifactId>
<packaging>pom</packaging>
<version>${revision}</version>
<properties>
<revision>1.0.1</revision>
</properties>
<modules>
<module>example-child</module>
</modules>
</project>
""",
spec -> spec.afterRecipe(pomXml -> assertThat(
pomXml.getMarkers().findFirst(MavenResolutionResult.class).orElseThrow()
.getModules()).isNotEmpty())
),
mavenProject("example-child",
pomXml(
"""
<project>
<parent>
<groupId>example</groupId>
<artifactId>example-root</artifactId>
<version>${revision}</version>
</parent>
<artifactId>example-child</artifactId>
</project>
"""
)
)
)
);
}
}

0 comments on commit 21183c7

Please sign in to comment.