Skip to content

Commit

Permalink
Manage maven version similarly as the other dependency versions are m…
Browse files Browse the repository at this point in the history
…anaged
  • Loading branch information
gzsombor committed Mar 25, 2024
1 parent 4e344e6 commit 638e9ee
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<maven.version>3.9.5</maven.version>
<maven.version>{{mavenVersion}}</maven.version>
</properties>

<build>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/generator/dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<archunit-junit5.version>1.2.1</archunit-junit5.version>
<cucumber.version>7.16.1</cucumber.version>
<!-- Maven Plugins -->
<maven.version>3.9.6</maven.version>
<os-maven-plugin.version>1.7.1</os-maven-plugin.version>
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 638e9ee

Please sign in to comment.