From 07bdcb6757076496598d89ef7dbb8720993be9ed Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Mon, 25 Mar 2024 19:07:01 +0100 Subject: [PATCH 1/3] 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") From e461957c4358389e8911db2a4289a4a283ab2c23 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Mon, 25 Mar 2024 23:34:38 +0100 Subject: [PATCH 2/3] Minimum supported maven version is 3.9.5 --- .../generator/buildtool/maven/domain/MavenModuleFactory.java | 4 ++-- .../maven/.mvn/wrapper/maven-wrapper.properties.mustache | 2 +- src/main/resources/generator/buildtool/maven/pom.xml.mustache | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) 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 1ff14021043..76898882e9f 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 @@ -35,7 +35,7 @@ public JHipsterModule buildMavenModule(JHipsterModuleProperties properties, Vers return moduleBuilder(properties) .context() .put("dasherizedBaseName", properties.projectBaseName().kebabCase()) - .put("mavenVersion", mavenVersion.version()) + .put("latestMavenVersion", mavenVersion.version()) .and() .prerequisites(JAVA_PREREQUISITES) .files() @@ -100,7 +100,7 @@ public JHipsterModule buildMavenWrapperModule(JHipsterModuleProperties propertie //@formatter:off return moduleBuilder(properties) .context() - .put("mavenVersion", mavenVersion.version()) + .put("latestMavenVersion", mavenVersion.version()) .and() .startupCommands() .maven("") diff --git a/src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties.mustache b/src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties.mustache index 944aa7c1e30..39aaba5e801 100644 --- a/src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties.mustache +++ 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/{{mavenVersion}}/apache-maven-{{mavenVersion}}-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/{{latestMavenVersion}}/apache-maven-{{latestMavenVersion}}-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 2da1637b6bf..452ba4cd9fd 100644 --- a/src/main/resources/generator/buildtool/maven/pom.xml.mustache +++ b/src/main/resources/generator/buildtool/maven/pom.xml.mustache @@ -18,7 +18,8 @@ UTF-8 UTF-8 - {{mavenVersion}} + + 3.9.5 From 9b1a87e02322625601d902fe335f15812b0c5a2d Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Mon, 25 Mar 2024 23:48:24 +0100 Subject: [PATCH 3/3] Fix maven test --- .../ConsistentMavenDependenciesDeclarationTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/ConsistentMavenDependenciesDeclarationTest.java b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/ConsistentMavenDependenciesDeclarationTest.java index 1d25fe433b4..6497888ba11 100644 --- a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/ConsistentMavenDependenciesDeclarationTest.java +++ b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/ConsistentMavenDependenciesDeclarationTest.java @@ -19,9 +19,15 @@ class ConsistentMavenDependenciesDeclarationTest { private static final String CURRENT_VERSIONS_FILE = "/generator/dependencies/pom.xml"; - public static Stream versions() { + public static Stream versions() { Model mavenModel = readMavenModel(); - return mavenModel.getProperties().keySet().stream().map(Object::toString).map(VersionSlug::new).map(Arguments::of); + return mavenModel + .getProperties() + .keySet() + .stream() + .map(Object::toString) + .filter(name -> !"maven.version".equals(name)) + .map(VersionSlug::new); } @MethodSource("versions")