diff --git a/src/main/java/tech/jhipster/lite/module/domain/JHipsterModulesApplyer.java b/src/main/java/tech/jhipster/lite/module/domain/JHipsterModulesApplyer.java index 2714c43c665..ef3769e6599 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/JHipsterModulesApplyer.java +++ b/src/main/java/tech/jhipster/lite/module/domain/JHipsterModulesApplyer.java @@ -124,11 +124,11 @@ private JavaBuildCommands buildDependenciesChanges(JHipsterModule module) { } private JavaBuildCommands buildProfilesChanges(JHipsterModule module) { - return module.javaBuildProfiles().buildChanges(javaVersions.get()); + return module.javaBuildProfiles().buildChanges(javaVersions.get(), projectDependencies.get(module.projectFolder())); } private JavaBuildCommands buildPluginsChanges(JHipsterModule module) { - return module.mavenPlugins().buildChanges(javaVersions.get()); + return module.mavenPlugins().buildChanges(javaVersions.get(), projectDependencies.get(module.projectFolder())); } private JavaBuildCommands buildMavenBuildExtensionsChanges(JHipsterModule module) { diff --git a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddDirectMavenPlugin.java b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddDirectMavenPlugin.java index 024bd8dc970..e8e0cd424b7 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddDirectMavenPlugin.java +++ b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddDirectMavenPlugin.java @@ -1,5 +1,6 @@ package tech.jhipster.lite.module.domain.javabuild.command; +import java.util.Collection; import java.util.Optional; import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileId; import tech.jhipster.lite.module.domain.javadependency.JavaDependencyVersion; @@ -11,12 +12,15 @@ public final class AddDirectMavenPlugin implements JavaBuildCommand, AddMavenPlu private final MavenPlugin plugin; private final Optional pluginVersion; private final Optional buildProfile; + private final Collection dependenciesVersions; - private AddDirectMavenPlugin(AddDirectMavenPluginBuilder builder) { - Assert.notNull("plugin", builder.plugin); - this.plugin = builder.plugin; - this.pluginVersion = Optional.ofNullable(builder.pluginVersion); - this.buildProfile = Optional.ofNullable(builder.buildProfile); + private AddDirectMavenPlugin(AddMavenPluginBuilder builder) { + Assert.notNull("plugin", builder.plugin()); + Assert.notNull("dependenciesVersions", builder.dependenciesVersions()); + this.plugin = builder.plugin(); + this.dependenciesVersions = builder.dependenciesVersions(); + this.pluginVersion = Optional.ofNullable(builder.pluginVersion()); + this.buildProfile = Optional.ofNullable(builder.buildProfile()); } @Override @@ -33,48 +37,11 @@ public Optional pluginVersion() { return pluginVersion; } - public static AddDirectMavenPluginPluginBuilder builder() { - return new AddDirectMavenPluginBuilder(); + public Collection dependenciesVersions() { + return dependenciesVersions; } - private static class AddDirectMavenPluginBuilder implements AddDirectMavenPluginPluginBuilder, AddDirectMavenPluginOptionalBuilder { - - private MavenPlugin plugin; - private JavaDependencyVersion pluginVersion; - private BuildProfileId buildProfile; - - private AddDirectMavenPluginBuilder() {} - - @Override - public AddDirectMavenPluginBuilder plugin(MavenPlugin plugin) { - this.plugin = plugin; - return this; - } - - @Override - public AddDirectMavenPluginOptionalBuilder pluginVersion(JavaDependencyVersion pluginVersion) { - this.pluginVersion = pluginVersion; - return this; - } - - @Override - public AddDirectMavenPluginOptionalBuilder buildProfile(BuildProfileId buildProfile) { - this.buildProfile = buildProfile; - return this; - } - - public AddDirectMavenPlugin build() { - return new AddDirectMavenPlugin(this); - } - } - - public interface AddDirectMavenPluginPluginBuilder { - AddDirectMavenPluginOptionalBuilder plugin(MavenPlugin javaBuildPlugin); - } - - public interface AddDirectMavenPluginOptionalBuilder { - AddDirectMavenPluginOptionalBuilder pluginVersion(JavaDependencyVersion version); - AddDirectMavenPluginOptionalBuilder buildProfile(BuildProfileId buildProfile); - AddDirectMavenPlugin build(); + public static AddMavenPluginPluginBuilder builder() { + return new AddMavenPluginBuilder<>(AddDirectMavenPlugin::new); } } diff --git a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddJavaDependency.java b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddJavaDependency.java index f5b3257e8ac..f75ac7bc40d 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddJavaDependency.java +++ b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddJavaDependency.java @@ -1,42 +1,7 @@ package tech.jhipster.lite.module.domain.javabuild.command; -import java.util.Collection; -import java.util.Optional; -import tech.jhipster.lite.module.domain.javabuild.VersionSlug; -import tech.jhipster.lite.module.domain.javadependency.DependencyId; import tech.jhipster.lite.module.domain.javadependency.JavaDependency; -import tech.jhipster.lite.module.domain.javadependency.JavaDependencyClassifier; -import tech.jhipster.lite.module.domain.javadependency.JavaDependencyScope; -import tech.jhipster.lite.module.domain.javadependency.JavaDependencyType; public sealed interface AddJavaDependency permits AddDirectJavaDependency, AddJavaDependencyManagement { JavaDependency dependency(); - - default Optional version() { - return dependency().version(); - } - - default Optional classifier() { - return dependency().classifier(); - } - - default JavaDependencyScope scope() { - return dependency().scope(); - } - - default boolean optional() { - return dependency().optional(); - } - - default DependencyId dependencyId() { - return dependency().id(); - } - - default Optional dependencyType() { - return dependency().type(); - } - - default Collection exclusions() { - return dependency().exclusions(); - } } diff --git a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPlugin.java b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPlugin.java index e6018efc628..09299b7618b 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPlugin.java +++ b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPlugin.java @@ -1,12 +1,14 @@ package tech.jhipster.lite.module.domain.javabuild.command; +import java.util.Collection; import java.util.Optional; import tech.jhipster.lite.module.domain.javabuild.VersionSlug; import tech.jhipster.lite.module.domain.javadependency.DependencyId; +import tech.jhipster.lite.module.domain.javadependency.JavaDependency; import tech.jhipster.lite.module.domain.javadependency.JavaDependencyVersion; import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin; import tech.jhipster.lite.module.domain.mavenplugin.MavenPluginConfiguration; -import tech.jhipster.lite.module.domain.mavenplugin.MavenPluginExecutions; +import tech.jhipster.lite.module.domain.mavenplugin.MavenPluginExecution; public interface AddMavenPlugin { MavenPlugin plugin(); @@ -19,10 +21,14 @@ default Optional configuration() { return plugin().configuration(); } - default Optional executions() { + default Collection executions() { return plugin().executions(); } + default Collection dependencies() { + return plugin().dependencies(); + } + default DependencyId dependencyId() { return plugin().dependencyId(); } diff --git a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginBuilder.java b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginBuilder.java new file mode 100644 index 00000000000..fc01d58a516 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginBuilder.java @@ -0,0 +1,65 @@ +package tech.jhipster.lite.module.domain.javabuild.command; + +import java.util.Collection; +import java.util.HashSet; +import java.util.function.Function; +import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileId; +import tech.jhipster.lite.module.domain.javadependency.JavaDependencyVersion; +import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin; + +class AddMavenPluginBuilder implements AddMavenPluginPluginBuilder, AddMavenPluginOptionalBuilder { + + private final Function, T> factory; + private MavenPlugin plugin; + private JavaDependencyVersion pluginVersion; + private BuildProfileId buildProfile; + private final Collection dependenciesVersions = new HashSet<>(); + + AddMavenPluginBuilder(Function, T> factory) { + this.factory = factory; + } + + public MavenPlugin plugin() { + return plugin; + } + + public JavaDependencyVersion pluginVersion() { + return pluginVersion; + } + + public BuildProfileId buildProfile() { + return buildProfile; + } + + public Collection dependenciesVersions() { + return dependenciesVersions; + } + + @Override + public AddMavenPluginBuilder plugin(MavenPlugin plugin) { + this.plugin = plugin; + return this; + } + + @Override + public AddMavenPluginOptionalBuilder pluginVersion(JavaDependencyVersion pluginVersion) { + this.pluginVersion = pluginVersion; + return this; + } + + @Override + public AddMavenPluginOptionalBuilder buildProfile(BuildProfileId buildProfile) { + this.buildProfile = buildProfile; + return this; + } + + @Override + public AddMavenPluginOptionalBuilder addDependencyVersion(JavaDependencyVersion dependencyVersion) { + this.dependenciesVersions.add(dependencyVersion); + return this; + } + + public T build() { + return factory.apply(this); + } +} diff --git a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginManagement.java b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginManagement.java index c982c5cf977..1987b7e576b 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginManagement.java +++ b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginManagement.java @@ -2,6 +2,7 @@ import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE; +import java.util.Collection; import java.util.Optional; import org.apache.commons.lang3.builder.ToStringBuilder; import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileId; @@ -15,12 +16,15 @@ public final class AddMavenPluginManagement implements JavaBuildCommand, AddMave private final MavenPlugin plugin; private final Optional pluginVersion; private final Optional buildProfile; + private final Collection dependenciesVersions; - private AddMavenPluginManagement(AddMavenPluginManagementBuilder builder) { - Assert.notNull("plugin", builder.plugin); - this.plugin = builder.plugin; - this.pluginVersion = Optional.ofNullable(builder.pluginVersion); - this.buildProfile = Optional.ofNullable(builder.buildProfile); + private AddMavenPluginManagement(AddMavenPluginBuilder builder) { + Assert.notNull("plugin", builder.plugin()); + Assert.notNull("dependenciesVersions", builder.dependenciesVersions()); + this.plugin = builder.plugin(); + this.dependenciesVersions = builder.dependenciesVersions(); + this.pluginVersion = Optional.ofNullable(builder.pluginVersion()); + this.buildProfile = Optional.ofNullable(builder.buildProfile()); } @Override @@ -37,50 +41,12 @@ public Optional buildProfile() { return buildProfile; } - public static AddMavenPluginManagementPluginBuilder builder() { - return new AddMavenPluginManagementBuilder(); + public Collection dependenciesVersions() { + return dependenciesVersions; } - private static class AddMavenPluginManagementBuilder - implements AddMavenPluginManagementPluginBuilder, AddMavenPluginManagementOptionalBuilder { - - private MavenPlugin plugin; - private JavaDependencyVersion pluginVersion; - private BuildProfileId buildProfile; - - private AddMavenPluginManagementBuilder() {} - - @Override - public AddMavenPluginManagementBuilder plugin(MavenPlugin plugin) { - this.plugin = plugin; - return this; - } - - @Override - public AddMavenPluginManagementOptionalBuilder pluginVersion(JavaDependencyVersion pluginVersion) { - this.pluginVersion = pluginVersion; - return this; - } - - @Override - public AddMavenPluginManagementOptionalBuilder buildProfile(BuildProfileId buildProfile) { - this.buildProfile = buildProfile; - return this; - } - - public AddMavenPluginManagement build() { - return new AddMavenPluginManagement(this); - } - } - - public interface AddMavenPluginManagementPluginBuilder { - AddMavenPluginManagementOptionalBuilder plugin(MavenPlugin plugin); - } - - public interface AddMavenPluginManagementOptionalBuilder { - AddMavenPluginManagementOptionalBuilder pluginVersion(JavaDependencyVersion version); - AddMavenPluginManagementOptionalBuilder buildProfile(BuildProfileId buildProfile); - AddMavenPluginManagement build(); + public static AddMavenPluginPluginBuilder builder() { + return new AddMavenPluginBuilder<>(AddMavenPluginManagement::new); } @Override @@ -88,7 +54,8 @@ public interface AddMavenPluginManagementOptionalBuilder { public String toString() { ToStringBuilder builder = new ToStringBuilder(this, SHORT_PREFIX_STYLE) .append("plugin", plugin) - .append("pluginVersion", pluginVersion.map(JavaDependencyVersion::toString).orElse("(empty)")); + .append("pluginVersion", pluginVersion.map(JavaDependencyVersion::toString).orElse("(empty)")) + .append("dependenciesVersions", pluginVersion.map(JavaDependencyVersion::toString).orElse("(empty)")); return builder.toString(); } } diff --git a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginOptionalBuilder.java b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginOptionalBuilder.java new file mode 100644 index 00000000000..e721177a928 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginOptionalBuilder.java @@ -0,0 +1,14 @@ +package tech.jhipster.lite.module.domain.javabuild.command; + +import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileId; +import tech.jhipster.lite.module.domain.javadependency.JavaDependencyVersion; + +public interface AddMavenPluginOptionalBuilder { + AddMavenPluginOptionalBuilder pluginVersion(JavaDependencyVersion version); + + AddMavenPluginOptionalBuilder buildProfile(BuildProfileId buildProfile); + + AddMavenPluginOptionalBuilder addDependencyVersion(JavaDependencyVersion javaDependencyVersion); + + T build(); +} diff --git a/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginPluginBuilder.java b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginPluginBuilder.java new file mode 100644 index 00000000000..c66a8f77ad2 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/module/domain/javabuild/command/AddMavenPluginPluginBuilder.java @@ -0,0 +1,7 @@ +package tech.jhipster.lite.module.domain.javabuild.command; + +import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin; + +public interface AddMavenPluginPluginBuilder { + AddMavenPluginOptionalBuilder plugin(MavenPlugin plugin); +} diff --git a/src/main/java/tech/jhipster/lite/module/domain/javabuildprofile/JHipsterModuleJavaBuildProfiles.java b/src/main/java/tech/jhipster/lite/module/domain/javabuildprofile/JHipsterModuleJavaBuildProfiles.java index 0b7aa24618e..c19a5008ec4 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/javabuildprofile/JHipsterModuleJavaBuildProfiles.java +++ b/src/main/java/tech/jhipster/lite/module/domain/javabuildprofile/JHipsterModuleJavaBuildProfiles.java @@ -13,6 +13,7 @@ import tech.jhipster.lite.module.domain.javabuild.command.SetBuildProperty; import tech.jhipster.lite.module.domain.javabuildprofile.JHipsterModuleJavaBuildProfile.JHipsterModuleJavaBuildProfileBuilder; import tech.jhipster.lite.module.domain.javadependency.JavaDependenciesVersions; +import tech.jhipster.lite.module.domain.javadependency.ProjectJavaDependencies; import tech.jhipster.lite.shared.error.domain.Assert; public class JHipsterModuleJavaBuildProfiles { @@ -27,10 +28,10 @@ public static JHipsterModuleJavaBuildProfilesBuilder builder(JHipsterModuleBuild return new JHipsterModuleJavaBuildProfilesBuilder(module); } - public JavaBuildCommands buildChanges(JavaDependenciesVersions versions) { + public JavaBuildCommands buildChanges(JavaDependenciesVersions versions, ProjectJavaDependencies projectJavaDependencies) { Stream addProfileCommands = profiles.stream().map(toAddProfileCommands()); Stream addPropertyCommands = profiles.stream().flatMap(toAddPropertyCommands()); - Stream mavenPluginCommands = profiles.stream().flatMap(toMavenPluginCommands(versions)); + Stream mavenPluginCommands = profiles.stream().flatMap(toMavenPluginCommands(versions, projectJavaDependencies)); Collection commands = Stream .of(addProfileCommands, addPropertyCommands, mavenPluginCommands) @@ -53,8 +54,11 @@ private Function> toAdd .map(property -> new SetBuildProperty(new BuildProperty(property.getKey(), property.getValue()), profile.id())); } - private Function> toMavenPluginCommands(JavaDependenciesVersions versions) { - return profile -> profile.mavenPlugins().buildChanges(versions, profile.id()).commands().stream(); + private Function> toMavenPluginCommands( + JavaDependenciesVersions versions, + ProjectJavaDependencies projectJavaDependencies + ) { + return profile -> profile.mavenPlugins().buildChanges(versions, projectJavaDependencies, profile.id()).commands().stream(); } public static class JHipsterModuleJavaBuildProfilesBuilder { diff --git a/src/main/java/tech/jhipster/lite/module/domain/javadependency/JavaDependency.java b/src/main/java/tech/jhipster/lite/module/domain/javadependency/JavaDependency.java index 18592a0ad52..5dbcea8345d 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/javadependency/JavaDependency.java +++ b/src/main/java/tech/jhipster/lite/module/domain/javadependency/JavaDependency.java @@ -53,7 +53,7 @@ Collection versionCommands(JavaDependenciesVersions currentVer return version().flatMap(toVersion(currentVersions, projectDependencies)).map(toSetVersionCommand()).map(List::of).orElse(List.of()); } - private Function> toVersion( + public static Function> toVersion( JavaDependenciesVersions currentVersions, ProjectJavaDependencies projectDependencies ) { @@ -64,7 +64,7 @@ private Function> toVersion( }; } - private Function> toVersionToUse(JavaDependencyVersion currentVersion) { + private static Function> toVersionToUse(JavaDependencyVersion currentVersion) { return version -> { if (version.equals(currentVersion)) { return Optional.empty(); diff --git a/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/JHipsterModuleMavenPlugins.java b/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/JHipsterModuleMavenPlugins.java index ee0e811588d..5c50830d4ad 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/JHipsterModuleMavenPlugins.java +++ b/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/JHipsterModuleMavenPlugins.java @@ -4,15 +4,20 @@ import java.util.Collection; import java.util.Optional; import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Stream; import tech.jhipster.lite.module.domain.javabuild.command.AddDirectMavenPlugin; -import tech.jhipster.lite.module.domain.javabuild.command.AddDirectMavenPlugin.AddDirectMavenPluginOptionalBuilder; +import tech.jhipster.lite.module.domain.javabuild.command.AddMavenPlugin; import tech.jhipster.lite.module.domain.javabuild.command.AddMavenPluginManagement; -import tech.jhipster.lite.module.domain.javabuild.command.AddMavenPluginManagement.AddMavenPluginManagementOptionalBuilder; +import tech.jhipster.lite.module.domain.javabuild.command.AddMavenPluginOptionalBuilder; +import tech.jhipster.lite.module.domain.javabuild.command.AddMavenPluginPluginBuilder; import tech.jhipster.lite.module.domain.javabuild.command.JavaBuildCommand; import tech.jhipster.lite.module.domain.javabuild.command.JavaBuildCommands; import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileId; import tech.jhipster.lite.module.domain.javadependency.JavaDependenciesVersions; +import tech.jhipster.lite.module.domain.javadependency.JavaDependency; +import tech.jhipster.lite.module.domain.javadependency.JavaDependencyVersion; +import tech.jhipster.lite.module.domain.javadependency.ProjectJavaDependencies; import tech.jhipster.lite.shared.error.domain.Assert; public class JHipsterModuleMavenPlugins { @@ -29,54 +34,61 @@ public static JHipsterModuleMavenPluginsBuilder builder(T parentModuleBui return new JHipsterModuleMavenPluginsBuilder<>(parentModuleBuilder); } - public JavaBuildCommands buildChanges(JavaDependenciesVersions versions) { - return buildChanges(versions, Optional.empty()); + public JavaBuildCommands buildChanges(JavaDependenciesVersions versions, ProjectJavaDependencies projectJavaDependencies) { + return buildChanges(versions, projectJavaDependencies, Optional.empty()); } - public JavaBuildCommands buildChanges(JavaDependenciesVersions versions, BuildProfileId buildProfile) { + public JavaBuildCommands buildChanges( + JavaDependenciesVersions versions, + ProjectJavaDependencies projectJavaDependencies, + BuildProfileId buildProfile + ) { Assert.notNull("buildProfile", buildProfile); - return buildChanges(versions, Optional.of(buildProfile)); + return buildChanges(versions, projectJavaDependencies, Optional.of(buildProfile)); } - private JavaBuildCommands buildChanges(JavaDependenciesVersions versions, Optional buildProfile) { + private JavaBuildCommands buildChanges( + JavaDependenciesVersions versions, + ProjectJavaDependencies projectJavaDependencies, + Optional buildProfile + ) { Assert.notNull("versions", versions); + Assert.notNull("projectJavaDependencies", projectJavaDependencies); - Stream managementCommands = pluginsManagement.stream().map(toAddMavenPluginManagement(versions, buildProfile)); - Stream pluginsCommands = plugins.stream().map(toAddDirectMavenPlugin(versions, buildProfile)); + Stream managementCommands = pluginsManagement + .stream() + .map(toAddMavenPlugin(versions, projectJavaDependencies, buildProfile, AddMavenPluginManagement::builder)); + Stream pluginsCommands = plugins + .stream() + .map(toAddMavenPlugin(versions, projectJavaDependencies, buildProfile, AddDirectMavenPlugin::builder)); return new JavaBuildCommands(Stream.concat(managementCommands, pluginsCommands).toList()); } - private static Function toAddMavenPluginManagement( + private static Function toAddMavenPlugin( JavaDependenciesVersions versions, - Optional buildProfile + ProjectJavaDependencies projectDependencies, + Optional buildProfile, + Supplier> builderFactory ) { return plugin -> { - AddMavenPluginManagementOptionalBuilder commandBuilder = AddMavenPluginManagement.builder().plugin(plugin); + AddMavenPluginOptionalBuilder commandBuilder = builderFactory.get().plugin(plugin); buildProfile.ifPresent(commandBuilder::buildProfile); - return plugin - .versionSlug() - .map(versions::get) - .map(commandBuilder::pluginVersion) - .map(AddMavenPluginManagementOptionalBuilder::build) - .orElse(commandBuilder.build()); + plugin + .dependencies() + .stream() + .flatMap(toDependencyVersion(versions, projectDependencies)) + .forEach(commandBuilder::addDependencyVersion); + plugin.versionSlug().map(versions::get).ifPresent(commandBuilder::pluginVersion); + return commandBuilder.build(); }; } - private static Function toAddDirectMavenPlugin( + private static Function> toDependencyVersion( JavaDependenciesVersions versions, - Optional buildProfile + ProjectJavaDependencies projectDependencies ) { - return plugin -> { - AddDirectMavenPluginOptionalBuilder commandBuilder = AddDirectMavenPlugin.builder().plugin(plugin); - buildProfile.ifPresent(commandBuilder::buildProfile); - return plugin - .versionSlug() - .map(versions::get) - .map(commandBuilder::pluginVersion) - .map(AddDirectMavenPluginOptionalBuilder::build) - .orElse(commandBuilder.build()); - }; + return dependency -> dependency.version().flatMap(JavaDependency.toVersion(versions, projectDependencies)).stream(); } public static class JHipsterModuleMavenPluginsBuilder { diff --git a/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/MavenPlugin.java b/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/MavenPlugin.java index 914cc117a76..f5765aa9126 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/MavenPlugin.java +++ b/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/MavenPlugin.java @@ -1,9 +1,8 @@ package tech.jhipster.lite.module.domain.mavenplugin; -import static java.util.function.Predicate.not; - import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Optional; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -12,7 +11,9 @@ import tech.jhipster.lite.module.domain.javabuild.GroupId; import tech.jhipster.lite.module.domain.javabuild.VersionSlug; import tech.jhipster.lite.module.domain.javadependency.DependencyId; +import tech.jhipster.lite.module.domain.javadependency.JavaDependency; import tech.jhipster.lite.module.domain.mavenplugin.MavenPluginExecution.MavenPluginExecutionOptionalBuilder; +import tech.jhipster.lite.shared.error.domain.Assert; import tech.jhipster.lite.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; public class MavenPlugin { @@ -20,13 +21,18 @@ public class MavenPlugin { private final DependencyId dependencyId; private final Optional versionSlug; private final Optional configuration; - private final Optional executions; + private final Collection executions; + private final Collection dependencies; private MavenPlugin(MavenPluginBuilder builder) { + Assert.notNull("executions", builder.executions); + Assert.notNull("dependencies", builder.dependencies); + dependencyId = DependencyId.of(builder.groupId, builder.artifactId); versionSlug = Optional.ofNullable(builder.versionSlug); configuration = Optional.ofNullable(builder.configuration); - executions = Optional.ofNullable(builder.executions).filter(not(Collection::isEmpty)).map(MavenPluginExecutions::new); + executions = builder.executions; + dependencies = builder.dependencies; } public static MavenPluginGroupIdBuilder builder() { @@ -41,7 +47,7 @@ public Optional configuration() { return configuration; } - public Optional executions() { + public Collection executions() { return executions; } @@ -49,6 +55,10 @@ public DependencyId dependencyId() { return dependencyId; } + public Collection dependencies() { + return dependencies; + } + private static class MavenPluginBuilder implements MavenPluginGroupIdBuilder, MavenPluginArtifactIdBuilder, MavenPluginOptionalBuilder { private GroupId groupId; @@ -56,6 +66,7 @@ private static class MavenPluginBuilder implements MavenPluginGroupIdBuilder, Ma private VersionSlug versionSlug; private MavenPluginConfiguration configuration; private final List executions = new ArrayList<>(); + private final Collection dependencies = new HashSet<>(); private MavenPluginBuilder() {} @@ -92,6 +103,12 @@ public MavenPluginOptionalBuilder addExecution(MavenPluginExecution executions) return this; } + @Override + public MavenPluginOptionalBuilder addDependency(JavaDependency dependency) { + this.dependencies.add(dependency); + return this; + } + @Override public MavenPlugin build() { return new MavenPlugin(this); @@ -134,6 +151,12 @@ default MavenPluginOptionalBuilder configuration(String configuration) { default MavenPluginOptionalBuilder addExecution(MavenPluginExecutionOptionalBuilder builder) { return addExecution(builder.build()); } + + MavenPluginOptionalBuilder addDependency(JavaDependency javaDependency); + + default MavenPluginOptionalBuilder addDependency(GroupId groupId, ArtifactId artifactId, VersionSlug version) { + return addDependency(JavaDependency.builder().groupId(groupId).artifactId(artifactId).versionSlug(version).build()); + } } @Override @@ -144,7 +167,8 @@ public String toString() { .append("dependencyId", dependencyId) .append("versionSlug", versionSlug.map(VersionSlug::toString).orElse("(empty)")) .append("configuration", configuration.map(MavenPluginConfiguration::toString).orElse("(empty)")) - .append("executions", executions.map(MavenPluginExecutions::toString).orElse("(empty)")); + .append("executions", executions) + .append("dependencies", dependencies); return builder.toString(); } } diff --git a/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/MavenPluginExecutions.java b/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/MavenPluginExecutions.java deleted file mode 100644 index e91971f0dfc..00000000000 --- a/src/main/java/tech/jhipster/lite/module/domain/mavenplugin/MavenPluginExecutions.java +++ /dev/null @@ -1,21 +0,0 @@ -package tech.jhipster.lite.module.domain.mavenplugin; - -import java.util.Collection; -import tech.jhipster.lite.shared.error.domain.Assert; -import tech.jhipster.lite.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; - -public record MavenPluginExecutions(Collection executions) { - public MavenPluginExecutions { - Assert.notEmpty("executions", executions); - } - - public Collection get() { - return executions; - } - - @Override - @ExcludeFromGeneratedCodeCoverage - public String toString() { - return executions.toString(); - } -} diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenCommandHandler.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenCommandHandler.java index b25f3476b48..8d97f7b3522 100644 --- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenCommandHandler.java +++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenCommandHandler.java @@ -9,7 +9,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Collection; import java.util.List; import java.util.function.Function; import java.util.function.Predicate; @@ -41,7 +40,6 @@ import tech.jhipster.lite.module.domain.javabuild.command.AddDirectMavenPlugin; import tech.jhipster.lite.module.domain.javabuild.command.AddGradlePlugin; import tech.jhipster.lite.module.domain.javabuild.command.AddJavaBuildProfile; -import tech.jhipster.lite.module.domain.javabuild.command.AddJavaDependency; import tech.jhipster.lite.module.domain.javabuild.command.AddJavaDependencyManagement; import tech.jhipster.lite.module.domain.javabuild.command.AddMavenBuildExtension; import tech.jhipster.lite.module.domain.javabuild.command.AddMavenPlugin; @@ -53,6 +51,7 @@ import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileActivation; import tech.jhipster.lite.module.domain.javabuildprofile.BuildProfileId; import tech.jhipster.lite.module.domain.javadependency.DependencyId; +import tech.jhipster.lite.module.domain.javadependency.JavaDependency; import tech.jhipster.lite.module.domain.javadependency.JavaDependencyClassifier; import tech.jhipster.lite.module.domain.javadependency.JavaDependencyScope; import tech.jhipster.lite.module.domain.mavenplugin.MavenBuildPhase; @@ -60,7 +59,6 @@ import tech.jhipster.lite.module.domain.mavenplugin.MavenPluginExecution; import tech.jhipster.lite.module.domain.mavenplugin.MavenPluginExecutionGoal; import tech.jhipster.lite.module.domain.mavenplugin.MavenPluginExecutionId; -import tech.jhipster.lite.module.domain.mavenplugin.MavenPluginExecutions; import tech.jhipster.lite.module.infrastructure.secondary.javadependency.JavaDependenciesCommandHandler; import tech.jhipster.lite.shared.enumeration.domain.Enums; import tech.jhipster.lite.shared.error.domain.Assert; @@ -212,7 +210,7 @@ private static Extension toMavenExtension(MavenBuildExtension mavenBuildExtensio public void handle(AddJavaDependencyManagement command) { Assert.notNull(COMMAND, command); - addDependencyTo(command, dependencyManagement().getDependencies()); + addDependencyTo(command.dependency(), dependencyManagement().getDependencies()); } private DependencyManagement dependencyManagement() { @@ -226,14 +224,14 @@ private DependencyManagement dependencyManagement() { public void handle(AddDirectJavaDependency command) { Assert.notNull(COMMAND, command); - addDependencyTo(command, pomModel.getDependencies()); + addDependencyTo(command.dependency(), pomModel.getDependencies()); } - private void addDependencyTo(AddJavaDependency command, List dependencies) { - if (command.scope() == JavaDependencyScope.TEST) { - dependencies.add(toMavenDependency(command)); + private void addDependencyTo(JavaDependency dependency, List dependencies) { + if (dependency.scope() == JavaDependencyScope.TEST) { + dependencies.add(toMavenDependency(dependency)); } else { - Dependency mavenDependency = toMavenDependency(command); + Dependency mavenDependency = toMavenDependency(dependency); insertDependencyBeforeFirstTestDependency(mavenDependency, dependencies); } @@ -252,19 +250,19 @@ private void insertDependencyBeforeFirstTestDependency(Dependency mavenDependenc } } - private Dependency toMavenDependency(AddJavaDependency command) { + private Dependency toMavenDependency(JavaDependency javaDependency) { Dependency mavenDependency = new Dependency(); - mavenDependency.setGroupId(command.dependencyId().groupId().get()); - mavenDependency.setArtifactId(command.dependencyId().artifactId().get()); - command.version().map(VersionSlug::mavenVariable).ifPresent(mavenDependency::setVersion); - command.classifier().map(JavaDependencyClassifier::get).ifPresent(mavenDependency::setClassifier); - command.dependencyType().map(type -> Enums.map(type, MavenType.class)).map(MavenType::key).ifPresent(mavenDependency::setType); - command.exclusions().stream().map(toMavenExclusion()).forEach(mavenDependency::addExclusion); - - if (command.scope() != JavaDependencyScope.COMPILE) { - mavenDependency.setScope(Enums.map(command.scope(), MavenScope.class).key()); + mavenDependency.setGroupId(javaDependency.id().groupId().get()); + mavenDependency.setArtifactId(javaDependency.id().artifactId().get()); + javaDependency.version().map(VersionSlug::mavenVariable).ifPresent(mavenDependency::setVersion); + javaDependency.classifier().map(JavaDependencyClassifier::get).ifPresent(mavenDependency::setClassifier); + javaDependency.type().map(type -> Enums.map(type, MavenType.class)).map(MavenType::key).ifPresent(mavenDependency::setType); + javaDependency.exclusions().stream().map(toMavenExclusion()).forEach(mavenDependency::addExclusion); + + if (javaDependency.scope() != JavaDependencyScope.COMPILE) { + mavenDependency.setScope(Enums.map(javaDependency.scope(), MavenScope.class).key()); } - if (command.optional()) { + if (javaDependency.optional()) { mavenDependency.setOptional(true); } @@ -285,6 +283,7 @@ public void handle(AddMavenPluginManagement command) { Assert.notNull(COMMAND, command); command.pluginVersion().ifPresent(version -> handle(new SetVersion(version))); + command.dependenciesVersions().forEach(version -> handle(new SetVersion(version))); PluginManagement pluginManagement = command .buildProfile() @@ -315,6 +314,7 @@ public void handle(AddDirectMavenPlugin command) { Assert.notNull(COMMAND, command); command.pluginVersion().ifPresent(version -> handle(new SetVersion(version))); + command.dependenciesVersions().forEach(version -> handle(new SetVersion(version))); BuildBase projectBuild = command.buildProfile().map(this::findProfile).map(this::profileBuild).orElse(projectBuild()); projectBuild.addPlugin(toMavenPlugin(command)); @@ -340,13 +340,8 @@ private Plugin toMavenPlugin(AddMavenPlugin command) { mavenPlugin.setGroupId(command.dependencyId().groupId().get()); command.versionSlug().map(VersionSlug::mavenVariable).ifPresent(mavenPlugin::setVersion); command.configuration().map(toMavenConfiguration()).ifPresent(mavenPlugin::setConfiguration); - command - .executions() - .stream() - .map(MavenPluginExecutions::get) - .flatMap(Collection::stream) - .map(toMavenExecution()) - .forEach(mavenPlugin::addExecution); + command.executions().stream().map(toMavenExecution()).forEach(mavenPlugin::addExecution); + command.dependencies().stream().map(this::toMavenDependency).forEach(mavenPlugin::addDependency); return mavenPlugin; } diff --git a/src/test/java/tech/jhipster/lite/module/domain/JHipsterModulesFixture.java b/src/test/java/tech/jhipster/lite/module/domain/JHipsterModulesFixture.java index a3fe08f65a5..67b5f53d6d9 100644 --- a/src/test/java/tech/jhipster/lite/module/domain/JHipsterModulesFixture.java +++ b/src/test/java/tech/jhipster/lite/module/domain/JHipsterModulesFixture.java @@ -92,7 +92,7 @@ public static JHipsterModule module() { .pluginManagement(mavenEnforcerPluginManagement()) .plugin(mavenEnforcerPlugin()) .and() - .javaBuildProfiles() + .javaBuildProfiles() .addProfile(localMavenProfile()) .activation(buildProfileActivation().activeByDefault(false)) .properties() @@ -186,8 +186,13 @@ public static JavaDependency defaultVersionDependency() { return javaDependency().groupId("org.springframework.boot").artifactId("spring-boot-starter").build(); } - public static JavaDependency dependencyWithVersion() { - return javaDependency().groupId("io.jsonwebtoken").artifactId("jjwt-api").versionSlug("json-web-token").build(); + public static JavaDependency dependencyWithVersionAndExclusion() { + return javaDependency() + .groupId("io.jsonwebtoken") + .artifactId("jjwt-jackson") + .versionSlug("json-web-token") + .addExclusion(DependencyId.of(new GroupId("com.fasterxml.jackson.core"), new ArtifactId("jackson-databind"))) + .build(); } public static JavaBuildCommands javaDependenciesCommands() { @@ -243,7 +248,11 @@ public static JHipsterModuleProperties testModuleProperties() { } public static JavaDependenciesVersions currentJavaDependenciesVersion() { - return new JavaDependenciesVersions(List.of(springBootVersion(), problemVersion(), mavenEnforcerVersion())); + return new JavaDependenciesVersions(List.of(springBootVersion(), problemVersion(), mavenEnforcerVersion(), jsonWebTokenVersion())); + } + + public static JavaDependencyVersion jsonWebTokenVersion() { + return new JavaDependencyVersion("json-web-token", "1.2.3"); } private static JavaDependencyVersion problemVersion() { @@ -317,6 +326,8 @@ public static MavenPlugin mavenEnforcerPluginManagement() { .groupId("org.apache.maven.plugins") .artifactId("maven-enforcer-plugin") .versionSlug("maven-enforcer-plugin") + .addDependency(dependencyWithVersionAndExclusion()) + .addDependency(groupId("io.jsonwebtoken"), artifactId("jjwt-jackson"), versionSlug("json-web-token")) .addExecution(pluginExecution().goals("enforce").id("enforce-versions")) .addExecution( pluginExecution() diff --git a/src/test/java/tech/jhipster/lite/module/domain/mavenplugin/JHipsterModuleMavenPluginsTest.java b/src/test/java/tech/jhipster/lite/module/domain/mavenplugin/JHipsterModuleMavenPluginsTest.java index 257b2df06cd..49b7a9854c6 100644 --- a/src/test/java/tech/jhipster/lite/module/domain/mavenplugin/JHipsterModuleMavenPluginsTest.java +++ b/src/test/java/tech/jhipster/lite/module/domain/mavenplugin/JHipsterModuleMavenPluginsTest.java @@ -8,6 +8,7 @@ import tech.jhipster.lite.module.domain.javabuild.command.AddDirectMavenPlugin; import tech.jhipster.lite.module.domain.javabuild.command.AddMavenPluginManagement; import tech.jhipster.lite.module.domain.javabuild.command.JavaBuildCommands; +import tech.jhipster.lite.module.domain.javadependency.ProjectJavaDependencies; @UnitTest class JHipsterModuleMavenPluginsTest { @@ -18,12 +19,17 @@ void shouldAddNewDependencyManagement() { .builder(emptyModuleBuilder()) .pluginManagement(mavenEnforcerPluginManagement()) .build() - .buildChanges(currentJavaDependenciesVersion()); + .buildChanges(currentJavaDependenciesVersion(), ProjectJavaDependencies.EMPTY); assertThat(changes.get()) .usingRecursiveFieldByFieldElementComparator() .containsExactly( - AddMavenPluginManagement.builder().plugin(mavenEnforcerPluginManagement()).pluginVersion(mavenEnforcerVersion()).build() + AddMavenPluginManagement + .builder() + .plugin(mavenEnforcerPluginManagement()) + .pluginVersion(mavenEnforcerVersion()) + .addDependencyVersion(jsonWebTokenVersion()) + .build() ); } @@ -31,12 +37,19 @@ void shouldAddNewDependencyManagement() { void shouldAddNewDependency() { JavaBuildCommands changes = JHipsterModuleMavenPlugins .builder(emptyModuleBuilder()) - .plugin(mavenEnforcerPlugin()) + .plugin(mavenEnforcerPluginManagement()) .build() - .buildChanges(currentJavaDependenciesVersion()); + .buildChanges(currentJavaDependenciesVersion(), ProjectJavaDependencies.EMPTY); assertThat(changes.get()) .usingRecursiveFieldByFieldElementComparator() - .containsExactly(AddDirectMavenPlugin.builder().plugin(mavenEnforcerPlugin()).build()); + .containsExactly( + AddDirectMavenPlugin + .builder() + .plugin(mavenEnforcerPluginManagement()) + .pluginVersion(mavenEnforcerVersion()) + .addDependencyVersion(jsonWebTokenVersion()) + .build() + ); } } diff --git a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemJHipsterModulesRepositoryTest.java b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemJHipsterModulesRepositoryTest.java index edecc00d254..d6930b1a3ef 100644 --- a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemJHipsterModulesRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemJHipsterModulesRepositoryTest.java @@ -21,7 +21,7 @@ class FileSystemJHipsterModulesRepositoryTest { private LogsSpy logs; @Test - void shouldApplyModule() { + void shouldApplyMavenModule() { JHipsterModule module = module(); // @formatter:off @@ -122,6 +122,7 @@ void shouldApplyModule() { """ ) .containing("") + .containing("") .containing( """ @@ -165,6 +166,19 @@ void shouldApplyModule() { + + + io.jsonwebtoken + jjwt-jackson + ${json-web-token.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + @@ -224,6 +238,19 @@ void shouldApplyModule() { + + + io.jsonwebtoken + jjwt-jackson + ${json-web-token.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + diff --git a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenCommandHandlerTest.java b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenCommandHandlerTest.java index b584712eecb..6ad8a6f1596 100644 --- a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenCommandHandlerTest.java +++ b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/javadependency/maven/MavenCommandHandlerTest.java @@ -9,7 +9,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.regex.Pattern; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import tech.jhipster.lite.TestFileUtils; @@ -65,8 +64,7 @@ void shouldEnforceIndentation() { } @Nested - @DisplayName("Set dependency version") - class MavenCommandHandlerSetVersionTest { + class HandleSetVersion { @Test void shouldAddPropertiesToPomWithOnlyRootDefined() { @@ -115,7 +113,6 @@ void shouldUpdateExistingProperty() { } @Nested - @DisplayName("Set build property") class HandleSetBuildProperty { @Nested @@ -254,7 +251,6 @@ void shouldUpdateExistingProperty() { } @Nested - @DisplayName("Add build profile") class HandleAddJavaBuildProfile { @Test @@ -353,8 +349,7 @@ void shouldAddProfileWithEmptyActivation() { } @Nested - @DisplayName("Remove dependency management") - class MavenCommandHandlerRemoveDependencyManagementTest { + class HandleRemoveJavaDependencyManagement { @Test void shouldNotRemoveUnknownDependency() { @@ -392,8 +387,7 @@ void shouldRemoveDependency() { } @Nested - @DisplayName("Add dependency management") - class MavenCommandHandlerAddDependencyManagementTest { + class HandleAddJavaDependencyManagement { @Test void shouldAddDependencyInPomWithoutDependenciesManagement() { @@ -468,8 +462,7 @@ void shouldAddDependencyManagementWithExclusion() { } @Nested - @DisplayName("Remove dependency") - class MavenCommandHandlerRemoveDependencyTest { + class HandleRemoveDirectJavaDependency { @Test void shouldNotRemoveUnknownDependency() { @@ -521,8 +514,7 @@ void shouldRemoveDependencyWithFullyMatchingId() { } @Nested - @DisplayName("Add dependency") - class MavenCommandHandlerAddDependencyTest { + class HandleAddDirectJavaDependency { @Test void shouldAddDependencyInPomWithoutDependencies() { @@ -653,8 +645,7 @@ void shouldAddCompileDependencyInPomWithEmptyDependencies() { } @Nested - @DisplayName("Add build plugin management") - class MavenCommandHandlerAddMavenPluginManagementTest { + class HandleAddMavenPluginManagement { @Nested class WithoutProfile { @@ -690,6 +681,20 @@ void shouldAddPropertyForPluginVersion() { assertThat(content(pom)).contains("1.1.1"); } + @Test + void shouldAddPropertyForPluginDependencyVersion() { + Path pom = projectWithPom("src/test/resources/projects/empty-maven/pom.xml"); + + AddMavenPluginManagement command = AddMavenPluginManagement + .builder() + .plugin(mavenEnforcerPluginManagement()) + .addDependencyVersion(new JavaDependencyVersion("json-web-token", "1.1.1")) + .build(); + new MavenCommandHandler(Indentation.DEFAULT, pom).handle(command); + + assertThat(content(pom)).contains("1.1.1"); + } + @Test void shouldAddBuildPluginManagementToPomWithoutPluginManagement() { Path pom = projectWithPom("src/test/resources/projects/maven-empty-build/pom.xml"); @@ -763,6 +768,19 @@ private String pluginManagement() { + + + io.jsonwebtoken + jjwt-jackson + ${json-web-token.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + @@ -812,7 +830,7 @@ void shouldAddBuildPluginToPomWithPlugins() { private void addMavenEnforcerPlugin(Path pom) { AddMavenPluginManagement command = AddMavenPluginManagement .builder() - .plugin(mavenEnforcerPlugin()) + .plugin(mavenEnforcerPluginManagement()) .pluginVersion(mavenEnforcerVersion()) .buildProfile(localMavenProfile()) .build(); @@ -828,6 +846,52 @@ private String plugins() { maven-enforcer-plugin + ${maven-enforcer-plugin.version} + + + enforce-versions + + enforce + + + + enforce-dependencyConvergence + + enforce + + + + + + false + + + + + + io.jsonwebtoken + jjwt-jackson + ${json-web-token.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + + + + + You are running an older version of Maven. JHipster requires at least Maven ${maven.version} + [${maven.version},) + + + You are running an incompatible version of Java. JHipster engine supports JDK 21+. + [21,22) + + + @@ -839,8 +903,7 @@ private String plugins() { } @Nested - @DisplayName("Add build plugin") - class MavenCommandHandlerAddBuildPluginTest { + class HandleAddDirectMavenPlugin { @Nested class WithoutProfile { @@ -864,6 +927,20 @@ void shouldAddPropertyForPluginVersion() { assertThat(content(pom)).contains("1.1.1"); } + @Test + void shouldAddPropertyForPluginDependencyVersion() { + Path pom = projectWithPom("src/test/resources/projects/empty-maven/pom.xml"); + + AddDirectMavenPlugin command = AddDirectMavenPlugin + .builder() + .plugin(mavenEnforcerPluginManagement()) + .addDependencyVersion(new JavaDependencyVersion("json-web-token", "1.1.1")) + .build(); + new MavenCommandHandler(Indentation.DEFAULT, pom).handle(command); + + assertThat(content(pom)).contains("1.1.1"); + } + @Test void shouldAddBuildPluginToPomWithEmptyBuild() { Path pom = projectWithPom("src/test/resources/projects/maven-empty-build/pom.xml"); @@ -921,13 +998,60 @@ void shouldAddMinimalBuildPluginExecutionToPomWithPlugins() { } private void addMavenEnforcerPlugin(Path pom) { - new MavenCommandHandler(Indentation.DEFAULT, pom).handle(AddDirectMavenPlugin.builder().plugin(mavenEnforcerPlugin()).build()); + new MavenCommandHandler(Indentation.DEFAULT, pom) + .handle(AddDirectMavenPlugin.builder().plugin(mavenEnforcerPluginManagement()).build()); } private String plugins() { return """ maven-enforcer-plugin + ${maven-enforcer-plugin.version} + + + enforce-versions + + enforce + + + + enforce-dependencyConvergence + + enforce + + + + + + false + + + + + + io.jsonwebtoken + jjwt-jackson + ${json-web-token.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + + + + + You are running an older version of Maven. JHipster requires at least Maven ${maven.version} + [${maven.version},) + + + You are running an incompatible version of Java. JHipster engine supports JDK 21+. + [21,22) + + + """; @@ -967,7 +1091,7 @@ private void addMavenEnforcerPlugin(Path pom) { .handle( AddDirectMavenPlugin .builder() - .plugin(mavenEnforcerPlugin()) + .plugin(mavenEnforcerPluginManagement()) .pluginVersion(mavenEnforcerVersion()) .buildProfile(localMavenProfile()) .build() @@ -982,6 +1106,52 @@ private String plugins() { maven-enforcer-plugin + ${maven-enforcer-plugin.version} + + + enforce-versions + + enforce + + + + enforce-dependencyConvergence + + enforce + + + + + + false + + + + + + io.jsonwebtoken + jjwt-jackson + ${json-web-token.version} + + + com.fasterxml.jackson.core + jackson-databind + + + + + + + + You are running an older version of Maven. JHipster requires at least Maven ${maven.version} + [${maven.version},) + + + You are running an incompatible version of Java. JHipster engine supports JDK 21+. + [21,22) + + + @@ -992,7 +1162,7 @@ private String plugins() { } @Nested - class AddBuildExtension { + class HandleAddMavenBuildExtension { @Test void shouldAddBuildExtensionInPomWithoutBuild() { @@ -1069,7 +1239,7 @@ void shouldAddBuildExtensionInPomWithExtensions() { } @Test - void addAddGradlePluginShouldNotBeHandled() { + void addGradlePluginCommandShouldNotBeHandled() { Path pom = projectWithPom("src/test/resources/projects/maven/pom.xml"); MavenCommandHandler commandHandler = new MavenCommandHandler(Indentation.DEFAULT, pom);