Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage maven version similarly as the other dependency versions are m… #9353

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("latestMavenVersion", 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("latestMavenVersion", 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/{{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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- Minimum supported Maven version -->
<maven.version>3.9.5</maven.version>
</properties>

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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maven wrapper version is already managed by renovate that automatically update it, so I don't really see the added value with theses changes:
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main goal is to have a way to get the current maven/gradle version from a module - as I try to create a jhipster module to create Mise configuration, so I could have a minimal, declarative project setup.
Any alternative idea, how and where can I get those values ? I would rather not duplicate that constant in that module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue is that by doing that you're breaking automatic update of maven wrapper.
The source of truth for maven wrapper version in jhipster-lite is src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties since it's handled by our automatic dependencies updater (renovate).

If for your specific needs you need to get the maven wrapper version used by jhipster-lite, you could implement a reader, in your own module, that will extract the version from src/main/resources/generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties:
mise/domain/MavenWrapperVersionReader.java

interface MavenWrapperVersionReader {
  Version readVersion();
}

implemented by
mise/infractructure/secondary/FilesystemMavenWrapperVersionReader.java

@Component
class FilesystemMavenWrapperVersionReader implements MavenWrapperVersionReader {
  @Override
  public Version readVersion() {
  // load generator/buildtool/maven/.mvn/wrapper/maven-wrapper.properties content from classpath
  // using a regexp to extract 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ class ConsistentMavenDependenciesDeclarationTest {

private static final String CURRENT_VERSIONS_FILE = "/generator/dependencies/pom.xml";

public static Stream<Arguments> versions() {
public static Stream<VersionSlug> 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")
Expand Down
Loading