From 638e9eec4465597505cc91f9747f45ff324ae55b Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Mon, 25 Mar 2024 19:07:01 +0100 Subject: [PATCH] Manage maven version similarly as the other dependency versions are managed --- .../application/MavenApplicationService.java | 15 ++++++++++++--- .../maven/domain/MavenModuleFactory.java | 11 ++++++++--- ...operties => maven-wrapper.properties.mustache} | 2 +- .../generator/buildtool/maven/pom.xml.mustache | 2 +- src/main/resources/generator/dependencies/pom.xml | 1 + .../maven/domain/MavenModuleFactoryTest.java | 8 +++++--- 6 files changed, 28 insertions(+), 11 deletions(-) rename src/main/resources/generator/buildtool/maven/.mvn/wrapper/{maven-wrapper.properties => maven-wrapper.properties.mustache} (92%) diff --git a/src/main/java/tech/jhipster/lite/generator/buildtool/maven/application/MavenApplicationService.java b/src/main/java/tech/jhipster/lite/generator/buildtool/maven/application/MavenApplicationService.java index 119f14dec11..ce1b8eadfca 100644 --- a/src/main/java/tech/jhipster/lite/generator/buildtool/maven/application/MavenApplicationService.java +++ b/src/main/java/tech/jhipster/lite/generator/buildtool/maven/application/MavenApplicationService.java @@ -3,22 +3,31 @@ import org.springframework.stereotype.Service; import tech.jhipster.lite.generator.buildtool.maven.domain.MavenModuleFactory; import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.javabuild.VersionSlug; +import tech.jhipster.lite.module.domain.javadependency.JavaDependenciesVersionsRepository; +import tech.jhipster.lite.module.domain.javadependency.Version; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; @Service public class MavenApplicationService { private final MavenModuleFactory factory; + private final JavaDependenciesVersionsRepository javaDependenciesVersionsRepository; - public MavenApplicationService() { + public MavenApplicationService(JavaDependenciesVersionsRepository javaDependenciesVersionsRepository) { + this.javaDependenciesVersionsRepository = javaDependenciesVersionsRepository; factory = new MavenModuleFactory(); } public JHipsterModule buildMavenModule(JHipsterModuleProperties properties) { - return factory.buildMavenModule(properties); + return factory.buildMavenModule(properties, getMavenVersion()); } public JHipsterModule buildMavenWrapperModule(JHipsterModuleProperties properties) { - return factory.buildMavenWrapperModule(properties); + return factory.buildMavenWrapperModule(properties, getMavenVersion()); + } + + private Version getMavenVersion() { + return javaDependenciesVersionsRepository.get().get(new VersionSlug("maven.version")).version(); } } diff --git a/src/main/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenModuleFactory.java index 53ac51b9b3c..1ff14021043 100644 --- a/src/main/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenModuleFactory.java @@ -8,6 +8,7 @@ import tech.jhipster.lite.module.domain.javabuild.GroupId; import tech.jhipster.lite.module.domain.javadependency.JavaDependency; import tech.jhipster.lite.module.domain.javadependency.JavaDependencyScope; +import tech.jhipster.lite.module.domain.javadependency.Version; import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; import tech.jhipster.lite.shared.error.domain.Assert; @@ -27,13 +28,14 @@ public class MavenModuleFactory { You need to have Java 21: - [JDK 21](https://openjdk.java.net/projects/jdk/21/)"""; - public JHipsterModule buildMavenModule(JHipsterModuleProperties properties) { + public JHipsterModule buildMavenModule(JHipsterModuleProperties properties, Version mavenVersion) { Assert.notNull("properties", properties); //@formatter:off return moduleBuilder(properties) .context() .put("dasherizedBaseName", properties.projectBaseName().kebabCase()) + .put("mavenVersion", mavenVersion.version()) .and() .prerequisites(JAVA_PREREQUISITES) .files() @@ -92,11 +94,14 @@ private static JavaDependency mockitoDependency() { .build(); } - public JHipsterModule buildMavenWrapperModule(JHipsterModuleProperties properties) { + public JHipsterModule buildMavenWrapperModule(JHipsterModuleProperties properties, Version mavenVersion) { Assert.notNull("properties", properties); //@formatter:off return moduleBuilder(properties) + .context() + .put("mavenVersion", mavenVersion.version()) + .and() .startupCommands() .maven("") .and() @@ -105,7 +110,7 @@ public JHipsterModule buildMavenWrapperModule(JHipsterModuleProperties propertie .addExecutable(SOURCE.file("mvnw.cmd"), to("mvnw.cmd")) .batch(SOURCE.append(".mvn/wrapper"), to(".mvn/wrapper")) .addFile("maven-wrapper.jar") - .addFile("maven-wrapper.properties") + .addTemplate("maven-wrapper.properties") .and() .and() .build(); diff --git a/src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties b/src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties.mustache similarity index 92% rename from src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties rename to src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties.mustache index 2f9352f713c..944aa7c1e30 100644 --- a/src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties +++ b/src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties.mustache @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/{{mavenVersion}}/apache-maven-{{mavenVersion}}-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/src/main/resources/generator/buildtool/maven/pom.xml.mustache b/src/main/resources/generator/buildtool/maven/pom.xml.mustache index c481b02e3da..2da1637b6bf 100644 --- a/src/main/resources/generator/buildtool/maven/pom.xml.mustache +++ b/src/main/resources/generator/buildtool/maven/pom.xml.mustache @@ -18,7 +18,7 @@ UTF-8 UTF-8 - 3.9.5 + {{mavenVersion}} diff --git a/src/main/resources/generator/dependencies/pom.xml b/src/main/resources/generator/dependencies/pom.xml index fd341b65b3a..02dd0baefa7 100644 --- a/src/main/resources/generator/dependencies/pom.xml +++ b/src/main/resources/generator/dependencies/pom.xml @@ -45,6 +45,7 @@ 1.2.1 7.16.1 + 3.9.6 1.7.1 0.6.1 3.3.1 diff --git a/src/test/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenModuleFactoryTest.java index bd1d0e65598..3241777e1f6 100644 --- a/src/test/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/buildtool/maven/domain/MavenModuleFactoryTest.java @@ -7,12 +7,14 @@ import tech.jhipster.lite.UnitTest; import tech.jhipster.lite.module.domain.JHipsterModule; import tech.jhipster.lite.module.domain.JHipsterModulesFixture; +import tech.jhipster.lite.module.domain.javadependency.Version; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; @UnitTest class MavenModuleFactoryTest { private static final MavenModuleFactory factory = new MavenModuleFactory(); + private static final Version MAVEN_VERSION = new Version("3.9.6"); @Test void shouldBuildMavenModule() { @@ -22,7 +24,7 @@ void shouldBuildMavenModule() { .projectName("JHipster test") .build(); - JHipsterModule module = factory.buildMavenModule(properties); + JHipsterModule module = factory.buildMavenModule(properties, MAVEN_VERSION); assertThatModuleWithFiles(module, readmeFile()) .hasFile("pom.xml") @@ -155,7 +157,7 @@ void shouldDeclareFailsafePluginAfterSurefirePluginInPomXml() { .projectName("JHipster test") .build(); - JHipsterModule module = factory.buildMavenModule(properties); + JHipsterModule module = factory.buildMavenModule(properties, MAVEN_VERSION); assertThatModuleWithFiles(module, readmeFile()) .hasFile("pom.xml") @@ -171,7 +173,7 @@ void shouldDeclareFailsafePluginAfterSurefirePluginInPomXml() { void shouldBuildMavenWrapperModule() { JHipsterModuleProperties properties = JHipsterModulesFixture.propertiesBuilder(TestFileUtils.tmpDirForTest()).build(); - JHipsterModule module = factory.buildMavenWrapperModule(properties); + JHipsterModule module = factory.buildMavenWrapperModule(properties, MAVEN_VERSION); assertThatModuleWithFiles(module, pomFile(), readmeFile()) .hasExecutableFiles("mvnw", "mvnw.cmd")