From e645e5c9b06011ab4f2ed57be1a87e9c5ae4f9e3 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 18 Dec 2024 15:47:04 +0100 Subject: [PATCH] Add VersionReference support to MavenPlugin and MavenExtension Closes gh-1243 --- .../kotlin/KotlinJpaMavenBuildCustomizer.java | 4 +- .../kotlin/KotlinMavenBuildCustomizer.java | 9 ++- .../KotlinMavenFullBuildCustomizer.java | 9 ++- .../DefaultMavenBuildCustomizerTests.java | 2 +- .../GroovyMavenBuildCustomizerTests.java | 3 +- .../KotlinJpaMavenBuildCustomizerTests.java | 3 +- .../KotlinMavenBuildCustomizerTests.java | 5 +- .../KotlinMavenFullBuildCustomizerTests.java | 5 +- .../buildsystem/maven/MavenBuildWriter.java | 6 +- .../buildsystem/maven/MavenExtension.java | 30 +++++++++- .../buildsystem/maven/MavenPlugin.java | 57 +++++++++++++++++-- .../buildsystem/maven/MavenBuildTests.java | 13 +++-- .../maven/MavenPluginContainerTests.java | 7 ++- 13 files changed, 120 insertions(+), 33 deletions(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java index ea16771b1d..6d288aa92c 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizer.java @@ -20,6 +20,7 @@ import io.spring.initializr.generator.project.ProjectDescription; import io.spring.initializr.generator.spring.build.BuildCustomizer; import io.spring.initializr.generator.spring.build.BuildMetadataResolver; +import io.spring.initializr.generator.version.VersionReference; import io.spring.initializr.metadata.InitializrMetadata; /** @@ -51,7 +52,8 @@ public void customize(MavenBuild build) { option.add("option", "all-open:annotation=jakarta.persistence.Embeddable"); }); }); - kotlinPlugin.dependency("org.jetbrains.kotlin", "kotlin-maven-noarg", "${kotlin.version}"); + kotlinPlugin.dependency("org.jetbrains.kotlin", "kotlin-maven-noarg", + VersionReference.ofProperty(KotlinMavenBuildCustomizer.KOTLIN_VERSION_PROPERTY)); }); } } diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizer.java index 51d8a9eaa2..42c33d6089 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizer.java @@ -21,7 +21,9 @@ import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.spring.build.BuildCustomizer; import io.spring.initializr.generator.version.Version; +import io.spring.initializr.generator.version.VersionProperty; import io.spring.initializr.generator.version.VersionRange; +import io.spring.initializr.generator.version.VersionReference; /** * {@link BuildCustomizer} for Kotlin projects build with Maven when Kotlin is supported @@ -34,6 +36,8 @@ */ class KotlinMavenBuildCustomizer implements BuildCustomizer { + static final VersionProperty KOTLIN_VERSION_PROPERTY = VersionProperty.of("kotlin.version"); + private static final VersionRange KOTLIN_ONE_EIGHT_OR_LATER = new VersionRange(Version.parse("1.8.0")); private final KotlinProjectSettings settings; @@ -44,7 +48,7 @@ class KotlinMavenBuildCustomizer implements BuildCustomizer { @Override public void customize(MavenBuild build) { - build.properties().version("kotlin.version", this.settings.getVersion()); + build.properties().version(KOTLIN_VERSION_PROPERTY, this.settings.getVersion()); build.settings() .sourceDirectory("${project.basedir}/src/main/kotlin") .testSourceDirectory("${project.basedir}/src/test/kotlin"); @@ -55,7 +59,8 @@ public void customize(MavenBuild build) { configuration.configure("compilerPlugins", (compilerPlugins) -> compilerPlugins.add("plugin", "spring")); }); - kotlinMavenPlugin.dependency("org.jetbrains.kotlin", "kotlin-maven-allopen", "${kotlin.version}"); + kotlinMavenPlugin.dependency("org.jetbrains.kotlin", "kotlin-maven-allopen", + VersionReference.ofProperty(KOTLIN_VERSION_PROPERTY)); }); String artifactId = KotlinMavenBuildCustomizer.KOTLIN_ONE_EIGHT_OR_LATER .match(Version.parse(this.settings.getVersion())) ? "kotlin-stdlib" : "kotlin-stdlib-jdk8"; diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizer.java index 84de6919eb..e57c52fd7e 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizer.java @@ -18,6 +18,7 @@ import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.spring.build.BuildCustomizer; +import io.spring.initializr.generator.version.VersionReference; /** * {@link BuildCustomizer} for Kotlin projects build with Maven when Kotlin is not @@ -35,12 +36,13 @@ class KotlinMavenFullBuildCustomizer implements BuildCustomizer { @Override public void customize(MavenBuild build) { - build.properties().version("kotlin.version", this.settings.getVersion()); + build.properties().version(KotlinMavenBuildCustomizer.KOTLIN_VERSION_PROPERTY, this.settings.getVersion()); build.settings() .sourceDirectory("${project.basedir}/src/main/kotlin") .testSourceDirectory("${project.basedir}/src/test/kotlin"); build.plugins().add("org.jetbrains.kotlin", "kotlin-maven-plugin", (kotlinMavenPlugin) -> { - kotlinMavenPlugin.version("${kotlin.version}"); + kotlinMavenPlugin + .versionReference(VersionReference.ofProperty(KotlinMavenBuildCustomizer.KOTLIN_VERSION_PROPERTY)); kotlinMavenPlugin.configuration((configuration) -> { configuration.configure("args", (args) -> this.settings.getCompilerArgs().forEach((arg) -> args.add("arg", arg))); @@ -51,7 +53,8 @@ public void customize(MavenBuild build) { kotlinMavenPlugin.execution("compile", (compile) -> compile.phase("compile").goal("compile")); kotlinMavenPlugin.execution("test-compile", (compile) -> compile.phase("test-compile").goal("test-compile")); - kotlinMavenPlugin.dependency("org.jetbrains.kotlin", "kotlin-maven-allopen", "${kotlin.version}"); + kotlinMavenPlugin.dependency("org.jetbrains.kotlin", "kotlin-maven-allopen", + VersionReference.ofProperty(KotlinMavenBuildCustomizer.KOTLIN_VERSION_PROPERTY)); }); } diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/build/maven/DefaultMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/build/maven/DefaultMavenBuildCustomizerTests.java index 949e63c9c3..f9843fd559 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/build/maven/DefaultMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/build/maven/DefaultMavenBuildCustomizerTests.java @@ -55,7 +55,7 @@ void customizeRegisterSpringBootPlugin() { assertThat(build.plugins().values()).singleElement().satisfies((mavenPlugin) -> { assertThat(mavenPlugin.getGroupId()).isEqualTo("org.springframework.boot"); assertThat(mavenPlugin.getArtifactId()).isEqualTo("spring-boot-maven-plugin"); - assertThat(mavenPlugin.getVersion()).isNull(); + assertThat(mavenPlugin.getVersionReference()).isNull(); }); } diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java index 714bab35e2..b1a7bb9aa4 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/groovy/GroovyMavenBuildCustomizerTests.java @@ -19,6 +19,7 @@ import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution; +import io.spring.initializr.generator.version.VersionReference; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -37,7 +38,7 @@ void groovyMavenPluginIsConfigured() { assertThat(build.plugins().values()).singleElement().satisfies((groovyPlugin) -> { assertThat(groovyPlugin.getGroupId()).isEqualTo("org.codehaus.gmavenplus"); assertThat(groovyPlugin.getArtifactId()).isEqualTo("gmavenplus-plugin"); - assertThat(groovyPlugin.getVersion()).isEqualTo("1.13.1"); + assertThat(groovyPlugin.getVersionReference()).isEqualTo(VersionReference.ofValue("1.13.1")); Configuration configuration = groovyPlugin.getConfiguration(); assertThat(configuration).isNull(); assertThat(groovyPlugin.getExecutions()).hasSize(1); diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java index 0ef96c344c..c62918d890 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinJpaMavenBuildCustomizerTests.java @@ -25,6 +25,7 @@ import io.spring.initializr.generator.project.MutableProjectDescription; import io.spring.initializr.generator.test.InitializrMetadataTestBuilder; import io.spring.initializr.generator.version.Version; +import io.spring.initializr.generator.version.VersionReference; import io.spring.initializr.metadata.Dependency; import io.spring.initializr.metadata.InitializrMetadata; import io.spring.initializr.metadata.support.MetadataBuildItemResolver; @@ -59,7 +60,7 @@ void customizeWhenJpaFacetPresentShouldAddKotlinJpaPlugin() { MavenPlugin.Dependency pluginDependency = plugin.getDependencies().get(0); assertThat(pluginDependency.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(pluginDependency.getArtifactId()).isEqualTo("kotlin-maven-noarg"); - assertThat(pluginDependency.getVersion()).isEqualTo("${kotlin.version}"); + assertThat(pluginDependency.getVersionReference()).isEqualTo(VersionReference.ofProperty("kotlin.version")); }); } diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java index 79b0c20ff0..efe6594cbf 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java @@ -25,6 +25,7 @@ import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Dependency; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting; import io.spring.initializr.generator.version.VersionProperty; +import io.spring.initializr.generator.version.VersionReference; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; @@ -61,7 +62,7 @@ void kotlinMavenPluginIsConfigured() { assertThat(build.plugins().values()).singleElement().satisfies((kotlinPlugin) -> { assertThat(kotlinPlugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(kotlinPlugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); - assertThat(kotlinPlugin.getVersion()).isNull(); + assertThat(kotlinPlugin.getVersionReference()).isNull(); Configuration configuration = kotlinPlugin.getConfiguration(); assertThat(configuration).isNotNull(); assertThat(configuration.getSettings()).hasSize(2); @@ -84,7 +85,7 @@ void kotlinMavenPluginIsConfigured() { Dependency allOpen = kotlinPlugin.getDependencies().get(0); assertThat(allOpen.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(allOpen.getArtifactId()).isEqualTo("kotlin-maven-allopen"); - assertThat(allOpen.getVersion()).isEqualTo("${kotlin.version}"); + assertThat(allOpen.getVersionReference()).isEqualTo(VersionReference.ofProperty("kotlin.version")); }); } diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java index 3beb4dc57c..929754ee97 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenFullBuildCustomizerTests.java @@ -22,6 +22,7 @@ import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting; import io.spring.initializr.generator.version.VersionProperty; +import io.spring.initializr.generator.version.VersionReference; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; @@ -58,7 +59,7 @@ void kotlinMavenPluginIsConfigured() { assertThat(build.plugins().values()).singleElement().satisfies((kotlinPlugin) -> { assertThat(kotlinPlugin.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(kotlinPlugin.getArtifactId()).isEqualTo("kotlin-maven-plugin"); - assertThat(kotlinPlugin.getVersion()).isEqualTo("${kotlin.version}"); + assertThat(kotlinPlugin.getVersionReference()).isEqualTo(VersionReference.ofProperty("kotlin.version")); Configuration configuration = kotlinPlugin.getConfiguration(); assertThat(configuration).isNotNull(); assertThat(configuration.getSettings()).hasSize(3); @@ -94,7 +95,7 @@ void kotlinMavenPluginIsConfigured() { Dependency allOpen = kotlinPlugin.getDependencies().get(0); assertThat(allOpen.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(allOpen.getArtifactId()).isEqualTo("kotlin-maven-allopen"); - assertThat(allOpen.getVersion()).isEqualTo("${kotlin.version}"); + assertThat(allOpen.getVersionReference()).isEqualTo(VersionReference.ofProperty("kotlin.version")); }); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java index 057e3c9ae9..612e556bc4 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildWriter.java @@ -422,7 +422,7 @@ private void writePlugin(IndentingWriter writer, MavenPlugin plugin) { writeElement(writer, "plugin", () -> { writeSingleElement(writer, "groupId", plugin.getGroupId()); writeSingleElement(writer, "artifactId", plugin.getArtifactId()); - writeSingleElement(writer, "version", plugin.getVersion()); + writeSingleElement(writer, "version", determineVersion(plugin.getVersionReference())); if (!plugin.isInherited()) { writeSingleElement(writer, "inherited", "false"); } @@ -468,7 +468,7 @@ private void writePluginDependency(IndentingWriter writer, MavenPlugin.Dependenc writeElement(writer, "dependency", () -> { writeSingleElement(writer, "groupId", dependency.getGroupId()); writeSingleElement(writer, "artifactId", dependency.getArtifactId()); - writeSingleElement(writer, "version", dependency.getVersion()); + writeSingleElement(writer, "version", determineVersion(dependency.getVersionReference())); }); } @@ -556,7 +556,7 @@ private void writeExtension(IndentingWriter writer, MavenExtension extension) { writeElement(writer, "extension", () -> { writeSingleElement(writer, "groupId", extension.getGroupId()); writeSingleElement(writer, "artifactId", extension.getArtifactId()); - writeSingleElement(writer, "version", extension.getVersion()); + writeSingleElement(writer, "version", determineVersion(extension.getVersionReference())); }); } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenExtension.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenExtension.java index 258a9edd4e..e9b306439f 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenExtension.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenExtension.java @@ -16,6 +16,8 @@ package io.spring.initializr.generator.buildsystem.maven; +import io.spring.initializr.generator.version.VersionReference; + /** * A build extension in a @{@link MavenBuild}. * @@ -28,7 +30,7 @@ public class MavenExtension { private final String artifactId; - private final String version; + private final VersionReference version; protected MavenExtension(Builder builder) { this.groupId = builder.groupId; @@ -54,9 +56,19 @@ public String getArtifactId() { /** * Return the version of the extension. - * @return the artifact id + * @return the version + * @deprecated for removal in favor of {@link #getVersionReference()} */ + @Deprecated(forRemoval = true) public String getVersion() { + return (this.version != null) ? this.version.getValue() : null; + } + + /** + * Return the version of the extension. + * @return the version + */ + public VersionReference getVersionReference() { return this.version; } @@ -66,7 +78,7 @@ public static class Builder { private final String artifactId; - private String version; + private VersionReference version; protected Builder(String groupId, String artifactId) { this.groupId = groupId; @@ -79,6 +91,18 @@ protected Builder(String groupId, String artifactId) { * @return this for method chaining */ public Builder version(String version) { + if (version == null) { + return versionReference(null); + } + return versionReference(VersionReference.ofValue(version)); + } + + /** + * Set the version of the extension. + * @param version the version of the extension + * @return this for method chaining + */ + public Builder versionReference(VersionReference version) { this.version = version; return this; } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java index 95418dbb46..7b7a206104 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/buildsystem/maven/MavenPlugin.java @@ -23,6 +23,8 @@ import java.util.Map; import java.util.function.Consumer; +import io.spring.initializr.generator.version.VersionReference; + /** * A plugin in a {@link MavenBuild}. * @@ -36,7 +38,7 @@ public class MavenPlugin { private final String artifactId; - private final String version; + private final VersionReference version; private final boolean extensions; @@ -77,10 +79,21 @@ public String getArtifactId() { /** * Return the version of the plugin or {@code null} if the version of the plugin is - * managed. + * managed. Also returns {@code null} if the version references a property. * @return the version or {@code null} + * @deprecated for removal in favor of {@link #getVersionReference()} */ + @Deprecated(forRemoval = true) public String getVersion() { + return (this.version != null) ? this.version.getValue() : null; + } + + /** + * Return the version of the plugin or {@code null} if the version of the plugin is + * managed. + * @return the version or {@code null} + */ + public VersionReference getVersionReference() { return this.version; } @@ -133,7 +146,7 @@ public static class Builder { private final String artifactId; - private String version; + private VersionReference version; private boolean extensions; @@ -157,6 +170,19 @@ protected Builder(String groupId, String artifactId) { * @return this for method chaining */ public Builder version(String version) { + if (version == null) { + return versionReference(null); + } + return versionReference(VersionReference.ofValue(version)); + } + + /** + * Set the version of the plugin or {@code null} if the version is managed by the + * project. + * @param version the version of the plugin or {@code null} + * @return this for method chaining + */ + public Builder versionReference(VersionReference version) { this.version = version; return this; } @@ -215,6 +241,17 @@ public Builder execution(String id, Consumer execution) { * @return this for method chaining */ public Builder dependency(String groupId, String artifactId, String version) { + return dependency(groupId, artifactId, (version != null) ? VersionReference.ofValue(version) : null); + } + + /** + * Add a plugin dependency. + * @param groupId the group ID of the dependency + * @param artifactId the artifact ID of the dependency + * @param version the version of the dependency + * @return this for method chaining + */ + public Builder dependency(String groupId, String artifactId, VersionReference version) { this.dependencies.add(new Dependency(groupId, artifactId, version)); return this; } @@ -487,9 +524,9 @@ public static final class Dependency { private final String artifactId; - private final String version; + private final VersionReference version; - private Dependency(String groupId, String artifactId, String version) { + private Dependency(String groupId, String artifactId, VersionReference version) { this.groupId = groupId; this.artifactId = artifactId; this.version = version; @@ -514,8 +551,18 @@ public String getArtifactId() { /** * Return the version of the plugin dependency. * @return the version + * @deprecated for removal in favor of {@link #getVersionReference()}. */ + @Deprecated(forRemoval = true) public String getVersion() { + return (this.version != null) ? this.version.getValue() : null; + } + + /** + * Return the version of the plugin dependency. + * @return the version + */ + public VersionReference getVersionReference() { return this.version; } diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java index cd00174961..6ee81a0265 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenBuildTests.java @@ -16,6 +16,7 @@ package io.spring.initializr.generator.buildsystem.maven; +import io.spring.initializr.generator.version.VersionReference; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -65,7 +66,7 @@ void mavenPluginManagementCanBeConfigured() { assertThat(build.pluginManagementPlugins().values()).singleElement().satisfies((testPlugin) -> { assertThat(testPlugin.getGroupId()).isEqualTo("com.example"); assertThat(testPlugin.getArtifactId()).isEqualTo("test-plugin"); - assertThat(testPlugin.getVersion()).isEqualTo("1.2.3"); + assertThat(testPlugin.getVersionReference()).isEqualTo(VersionReference.ofValue("1.2.3")); }); } @@ -78,7 +79,7 @@ void mavenPluginCanBeConfigured() { assertThat(build.plugins().values()).singleElement().satisfies((testPlugin) -> { assertThat(testPlugin.getGroupId()).isEqualTo("com.example"); assertThat(testPlugin.getArtifactId()).isEqualTo("test-plugin"); - assertThat(testPlugin.getVersion()).isNull(); + assertThat(testPlugin.getVersionReference()).isNull(); assertThat(testPlugin.getExecutions()).hasSize(1); assertThat(testPlugin.getExecutions().get(0).getId()).isEqualTo("first"); assertThat(testPlugin.getExecutions().get(0).getGoals()).containsExactly("run-this"); @@ -93,7 +94,7 @@ void mavenPluginVersionCanBeAmended() { assertThat(build.plugins().values()).singleElement().satisfies((testPlugin) -> { assertThat(testPlugin.getGroupId()).isEqualTo("com.example"); assertThat(testPlugin.getArtifactId()).isEqualTo("test-plugin"); - assertThat(testPlugin.getVersion()).isEqualTo("1.0.0"); + assertThat(testPlugin.getVersionReference()).isEqualTo(VersionReference.ofValue("1.0.0")); }); } @@ -106,7 +107,7 @@ void mavenPluginVersionCanBeAmendedWithCustomizer() { assertThat(build.plugins().values()).singleElement().satisfies((testPlugin) -> { assertThat(testPlugin.getGroupId()).isEqualTo("com.example"); assertThat(testPlugin.getArtifactId()).isEqualTo("test-plugin"); - assertThat(testPlugin.getVersion()).isNull(); + assertThat(testPlugin.getVersionReference()).isNull(); }); } @@ -118,7 +119,7 @@ void mavenPluginVersionIsNotLostOnAmend() { assertThat(build.plugins().values()).singleElement().satisfies((testPlugin) -> { assertThat(testPlugin.getGroupId()).isEqualTo("com.example"); assertThat(testPlugin.getArtifactId()).isEqualTo("test-plugin"); - assertThat(testPlugin.getVersion()).isEqualTo("1.0.0"); + assertThat(testPlugin.getVersionReference()).isEqualTo(VersionReference.ofValue("1.0.0")); }); } @@ -224,7 +225,7 @@ void mavenPluginManagementInProfileCanBeConfigured() { .satisfies((testPlugin) -> { assertThat(testPlugin.getGroupId()).isEqualTo("com.example"); assertThat(testPlugin.getArtifactId()).isEqualTo("test-plugin"); - assertThat(testPlugin.getVersion()).isEqualTo("1.2.3"); + assertThat(testPlugin.getVersionReference()).isEqualTo(VersionReference.ofValue("1.2.3")); })); } diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginContainerTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginContainerTests.java index 4722539da4..85f0c9054a 100644 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginContainerTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/buildsystem/maven/MavenPluginContainerTests.java @@ -16,6 +16,7 @@ package io.spring.initializr.generator.buildsystem.maven; +import io.spring.initializr.generator.version.VersionReference; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -35,7 +36,7 @@ void addPlugin() { assertThat(pluginContainer.values()).singleElement().satisfies((plugin) -> { assertThat(plugin.getGroupId()).isEqualTo("com.example"); assertThat(plugin.getArtifactId()).isEqualTo("test-plugin"); - assertThat(plugin.getVersion()).isNull(); + assertThat(plugin.getVersionReference()).isNull(); }); } @@ -47,7 +48,7 @@ void addPluginWithConsumer() { assertThat(pluginContainer.values()).singleElement().satisfies((plugin) -> { assertThat(plugin.getGroupId()).isEqualTo("com.example"); assertThat(plugin.getArtifactId()).isEqualTo("test-plugin"); - assertThat(plugin.getVersion()).isEqualTo("1.0"); + assertThat(plugin.getVersionReference()).isEqualTo(VersionReference.ofValue("1.0")); assertThat(plugin.getExecutions()).hasSize(1); assertThat(plugin.getExecutions().get(0).getId()).isEqualTo("first"); assertThat(plugin.getExecutions().get(0).getGoals()).containsExactly("run-this"); @@ -62,7 +63,7 @@ void addPluginSeveralTimeReuseConfiguration() { assertThat(pluginContainer.values()).singleElement().satisfies((plugin) -> { assertThat(plugin.getGroupId()).isEqualTo("com.example"); assertThat(plugin.getArtifactId()).isEqualTo("test-plugin"); - assertThat(plugin.getVersion()).isEqualTo("2.0"); + assertThat(plugin.getVersionReference()).isEqualTo(VersionReference.ofValue("2.0")); }); }