diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/application/FrontendJavaBuildToolApplicationService.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/application/FrontendJavaBuildToolApplicationService.java index 2a9dcf9a23c..ee3c5263327 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/application/FrontendJavaBuildToolApplicationService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/application/FrontendJavaBuildToolApplicationService.java @@ -22,4 +22,8 @@ public JHipsterModule buildFrontendMavenModule(JHipsterModuleProperties properti public JHipsterModule buildFrontendGradleModule(JHipsterModuleProperties properties) { return factory.buildFrontendGradleModule(properties); } + + public JHipsterModule buildFrontendMavenCacheModule(JHipsterModuleProperties properties) { + return factory.buildFrontendMavenCacheModule(properties); + } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendJavaBuildToolModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendJavaBuildToolModuleFactory.java index 0ff1c99aee1..ddefa9539b2 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendJavaBuildToolModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendJavaBuildToolModuleFactory.java @@ -29,16 +29,29 @@ public FrontendJavaBuildToolModuleFactory(NpmVersions npmVersions) { } public JHipsterModule buildFrontendMavenModule(JHipsterModuleProperties properties) { + Assert.notNull("properties", properties); + //@formatter:off return commonModuleFiles(properties) .javaBuildProperties() .set(buildPropertyKey("node.version"), buildPropertyValue("v" + npmVersions.nodeVersion().get())) .set(buildPropertyKey("npm.version"), buildPropertyValue(npmVersions.get("npm", NpmVersionSource.COMMON).get())) .and() + .mavenPlugins() + .plugin(frontendMavenPlugin()) + .and() + .build(); + //@formatter:on + } + + public JHipsterModule buildFrontendMavenCacheModule(JHipsterModuleProperties properties) { + Assert.notNull("properties", properties); + + //@formatter:off + return moduleBuilder(properties) .mavenPlugins() .plugin(checksumPlugin()) .plugin(antrunPlugin()) - .plugin(frontendMavenPlugin()) .and() .build(); //@formatter:on diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/infrastructure/primary/FrontendJavaBuildToolModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/infrastructure/primary/FrontendJavaBuildToolModuleConfiguration.java index 3a87a2f72cb..6d3af7badaf 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/infrastructure/primary/FrontendJavaBuildToolModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/infrastructure/primary/FrontendJavaBuildToolModuleConfiguration.java @@ -6,19 +6,20 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import tech.jhipster.lite.generator.server.javatool.frontendmaven.application.FrontendJavaBuildToolApplicationService; -import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization; -import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition; -import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource; +import tech.jhipster.lite.module.domain.resource.*; @Configuration class FrontendJavaBuildToolModuleConfiguration { + private static final String[] TAGS = { "server", "tools" }; + private static final String FRONTEND_JAVA_PLUGIN = "Frontend Java Plugin"; + @Bean JHipsterModuleResource frontendMavenModule(FrontendJavaBuildToolApplicationService frontendJavaBuildTool) { return JHipsterModuleResource.builder() .slug(FRONTEND_MAVEN_PLUGIN) .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addIndentation().build()) - .apiDoc("Frontend Java Plugin", "Add Frontend Maven Plugin") + .apiDoc(FRONTEND_JAVA_PLUGIN, "Add Frontend Maven Plugin") .organization( JHipsterModuleOrganization.builder() .feature(FRONTEND_JAVA_BUILD_TOOL_PLUGIN) @@ -27,16 +28,27 @@ JHipsterModuleResource frontendMavenModule(FrontendJavaBuildToolApplicationServi .addDependency(MAVEN_JAVA) .build() ) - .tags("server", "tools") + .tags(TAGS) .factory(frontendJavaBuildTool::buildFrontendMavenModule); } + @Bean + JHipsterModuleResource frontendMavenCacheModule(FrontendJavaBuildToolApplicationService frontendJavaBuildTool) { + return JHipsterModuleResource.builder() + .slug(FRONTEND_MAVEN_PLUGIN_CACHE) + .propertiesDefinition(JHipsterModulePropertiesDefinition.EMPTY) + .apiDoc(FRONTEND_JAVA_PLUGIN, "Add cache - by computing resources checksum - to avoid rebuilding frontend on successive maven builds") + .organization(JHipsterModuleOrganization.builder().addDependency(FRONTEND_MAVEN_PLUGIN).build()) + .tags(TAGS) + .factory(frontendJavaBuildTool::buildFrontendMavenCacheModule); + } + @Bean JHipsterModuleResource frontendGradleModule(FrontendJavaBuildToolApplicationService frontendJavaBuildTool) { return JHipsterModuleResource.builder() .slug(NODE_GRADLE_PLUGIN) .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addIndentation().build()) - .apiDoc("Frontend Java Plugin", "Add node-gradle plugin for building frontend with Gradle") + .apiDoc(FRONTEND_JAVA_PLUGIN, "Add node-gradle plugin for building frontend with Gradle") .organization( JHipsterModuleOrganization.builder() .feature(FRONTEND_JAVA_BUILD_TOOL_PLUGIN) @@ -45,7 +57,7 @@ JHipsterModuleResource frontendGradleModule(FrontendJavaBuildToolApplicationServ .addDependency(GRADLE_JAVA) .build() ) - .tags("server", "tools") + .tags(TAGS) .factory(frontendJavaBuildTool::buildFrontendGradleModule); } } diff --git a/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java b/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java index 18ffdffc0c8..61bc37c4962 100644 --- a/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java +++ b/src/main/java/tech/jhipster/lite/generator/slug/domain/JHLiteModuleSlug.java @@ -33,6 +33,7 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory { FLYWAY_MYSQL("flyway-mysql"), FLYWAY_POSTGRESQL("flyway-postgresql"), FRONTEND_MAVEN_PLUGIN("frontend-maven-plugin"), + FRONTEND_MAVEN_PLUGIN_CACHE("frontend-maven-plugin-cache"), FRONT_HEXAGONAL_ARCHITECTURE("front-hexagonal-architecture"), NODE_GRADLE_PLUGIN("node-gradle-plugin"), GATEWAY("gateway"), diff --git a/src/test/features/server/javatool/frontend-java-build-tool.feature b/src/test/features/server/javatool/frontend-java-build-tool.feature index cf8c90d5623..9254435d0da 100644 --- a/src/test/features/server/javatool/frontend-java-build-tool.feature +++ b/src/test/features/server/javatool/frontend-java-build-tool.feature @@ -7,6 +7,11 @@ Feature: Frontend server module Then I should have files in "src/main/java/tech/jhipster/chips/wire/frontend/infrastructure/primary" | RedirectionResource.java | + Scenario: Should apply frontend-maven-plugin-cache module + When I apply "frontend-maven-plugin-cache" module to default project with maven file + | packageName | tech.jhipster.chips | + Then I should have "checksum-maven-plugin" in "pom.xml" + Scenario: Should apply frontend server gradle module When I apply "node-gradle-plugin" module to default project with gradle build | packageName | tech.jhipster.chips | diff --git a/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendJavaBuildToolModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendJavaBuildToolModuleFactoryTest.java index 3dc0eda89bf..e80ac63a01d 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendJavaBuildToolModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendJavaBuildToolModuleFactoryTest.java @@ -40,6 +40,76 @@ void shouldBuildFrontendMavenModule() { .hasFile("pom.xml") .containing(" v16.0.0") .containing(" 4.0.0") + .notContaining("checksum-maven-plugin") + .containing( + """ + + com.github.eirslett + frontend-maven-plugin + ${frontend-maven-plugin.version} + + + install-node-and-npm + + install-node-and-npm + + + ${node.version} + ${npm.version} + + + + npm install + + npm + + + + build front + generate-resources + + npm + + + run build + + ${project.version} + + false + + + + front test + test + + npm + + + run test:coverage + false + + + + + ${project.build.directory} + + + """ + ) + .and() + .hasPrefixedFiles( + "src/main/java/tech/jhipster/jhlitest/wire/frontend", + "infrastructure/primary/RedirectionResource.java", + "package-info.java" + ); + } + + @Test + void shouldBuildFrontendMavenCacheModule() { + JHipsterModule module = factory.buildFrontendMavenCacheModule(getProperties()); + + assertThatModuleWithFiles(module, pomFile()) + .hasFile("pom.xml") .containing( """ @@ -118,67 +188,6 @@ void shouldBuildFrontendMavenModule() { """ - ) - .containing( - """ - - com.github.eirslett - frontend-maven-plugin - ${frontend-maven-plugin.version} - - - install-node-and-npm - - install-node-and-npm - - - ${node.version} - ${npm.version} - - - - npm install - - npm - - - - build front - generate-resources - - npm - - - run build - - ${project.version} - - false - - - - front test - test - - npm - - - run test:coverage - false - - - - - ${project.build.directory} - - - """ - ) - .and() - .hasPrefixedFiles( - "src/main/java/tech/jhipster/jhlitest/wire/frontend", - "infrastructure/primary/RedirectionResource.java", - "package-info.java" ); } }