Repository: jhipster/jhipster-lite
Pull request #10264 (2024-07-12 16:01:06)

feature(protobuf): use ascopes maven protobuf plugin instead of xolstice one
This plugin is actively maintained, is simpler to use and aims to be compatible with maven 4

https://github.com/ascopes/protobuf-maven-plugin?tab=readme-ov-file#why-do-we-need-another-plugin


Patch:
diff --git a/sonar-project.properties b/sonar-project.properties
index a0eecc50b..de468efa4 100644
--- a/sonar-project.properties
+++ b/sonar-project.properties
@@ -17,17 +17,7 @@ sonar.testExecutionReportPaths=target/test-results/TESTS-results-sonar.xml
 sonar.javascript.lcov.reportPaths=target/test-results/lcov.info
 
 sonar.sourceEncoding=UTF-8
-sonar.exclusions=\
-  src/main/resources/**,\
-  src/test/resources/projects/**/*.*,\
-  src/main/webapp/main.ts,\
-  src/main/webapp/app/main.ts,\
-  src/main/webapp/content/**/*.*,\
-  src/main/webapp/i18n/*.js,\
-  target/classes/static/**/*.*,\
-  src/main/glyph/css/**,\
-  src/main/webapp/app/router/index.ts,\
-  src/main/webapp/app/common/primary/applicationlistener/WindowApplicationListener.ts
+sonar.exclusions=src/main/webapp/main.ts, src/main/webapp/app/main.ts, src/main/webapp/content/**/*.*, src/main/webapp/i18n/*.js, target/classes/static/**/*.*, src/main/resources/**, src/main/webapp/app/router/index.ts, src/main/glyph/css/**, src/main/webapp/app/common/primary/applicationlistener/WindowApplicationListener.ts
 
 sonar.typescript.tsconfigPath=tsconfig.json
 
@@ -109,6 +99,5 @@ sonar.issue.ignore.multicriteria.S4649.ruleKey=css:S4649
 # Ignore duplication for Arguments replacer (rule is deprecated)
 sonar.issue.ignore.multicriteria.duplicated.resourceKey=src/main/java/**
 sonar.issue.ignore.multicriteria.duplicated.ruleKey=common-java:DuplicatedBlocks
-sonar.cpd.exclusions=\
-  src/main/java/tech/jhipster/lite/error/infrastructure/primary/ArgumentsReplacer.java,\
-  src/main/java/tech/jhipster/lite/module/domain/file/ArgumentsReplacer.java
+sonar.cpd.exclusions=src/main/java/tech/jhipster/lite/error/infrastructure/primary/ArgumentsReplacer.java,src/main/java/tech/jhipster/lite/module/domain/file/ArgumentsReplacer.java
+
diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/protobuf/domain/ProtobufModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/protobuf/domain/ProtobufModuleFactory.java
index b96eced6c..6d7c1025b 100644
--- a/src/main/java/tech/jhipster/lite/generator/server/javatool/protobuf/domain/ProtobufModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/protobuf/domain/ProtobufModuleFactory.java
@@ -53,9 +53,6 @@ public class ProtobufModuleFactory {
         .pluginManagement(protobufMavenPluginManagement())
         .plugin(protobufMavenPluginBuilder().build())
         .and()
-      .mavenBuildExtensions()
-        .addExtension(groupId("kr.motd.maven"), artifactId("os-maven-plugin"), versionSlug("os-maven-plugin"))
-        .and()
       .gradlePlugins()
         .plugin(protobufGradlePlugin())
         .and()
@@ -85,15 +82,19 @@ public class ProtobufModuleFactory {
       .versionSlug("protobuf-maven-plugin")
       .configuration(
         """
-        <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
+        <protocVersion>${protobuf.version}</protocVersion>
+        <sourceDirectories>
+          <sourceDirectory>src/main/proto</sourceDirectory>
+        </sourceDirectories>
+        <failOnMissingSources>false</failOnMissingSources>
         """
       )
-      .addExecution(pluginExecution().goals("compile"))
+      .addExecution(pluginExecution().goals("generate"))
       .build();
   }
 
   private MavenPluginOptionalBuilder protobufMavenPluginBuilder() {
-    return mavenPlugin().groupId("org.xolstice.maven.plugins").artifactId("protobuf-maven-plugin");
+    return mavenPlugin().groupId("io.github.ascopes").artifactId("protobuf-maven-plugin");
   }
 
   public JHipsterModule buildProtobufBackwardsCompatibilityCheckModule(JHipsterModuleProperties properties) {
@@ -102,6 +103,9 @@ public class ProtobufModuleFactory {
       .files()
         .add(MAIN_SOURCE.append("proto.lock"), to("src/main/proto/proto.lock"))
         .and()
+      .mavenBuildExtensions()
+        .addExtension(groupId("kr.motd.maven"), artifactId("os-maven-plugin"), versionSlug("os-maven-plugin"))
+        .and()
       .mavenPlugins()
         .pluginManagement(protoBackwardsCompatibilityMavenPluginManagement())
         .plugin(protoBackwardsCompatibilityMavenPluginBuilder().build())
diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/protobuf/infrastructure/primary/ProtobufModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/protobuf/infrastructure/primary/ProtobufModuleConfiguration.java
index f7f3683b4..9448e60d3 100644
--- a/src/main/java/tech/jhipster/lite/generator/server/javatool/protobuf/infrastructure/primary/ProtobufModuleConfiguration.java
+++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/protobuf/infrastructure/primary/ProtobufModuleConfiguration.java
@@ -3,11 +3,8 @@ package tech.jhipster.lite.generator.server.javatool.protobuf.infrastructure.pri
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import tech.jhipster.lite.generator.server.javatool.protobuf.application.ProtobufApplicationService;
-import tech.jhipster.lite.generator.slug.domain.JHLiteFeatureSlug;
 import tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug;
-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 ProtobufModuleConfiguration {
@@ -18,7 +15,7 @@ class ProtobufModuleConfiguration {
       .slug(JHLiteModuleSlug.PROTOBUF)
       .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().addIndentation().build())
       .apiDoc("Java", "Add protobuf support")
-      .organization(JHipsterModuleOrganization.builder().addDependency(JHLiteFeatureSlug.JAVA_BUILD_TOOL).build())
+      .organization(JHipsterModuleOrganization.builder().addDependency(JHLiteModuleSlug.JAVA_BASE).build())
       .tags("server", "protobuf")
       .factory(protobuf::buildProtobufModule);
   }
diff --git a/src/main/resources/generator/dependencies/pom.xml b/src/main/resources/generator/dependencies/pom.xml
index c0d75ff28..1cea51cf7 100644
--- a/src/main/resources/generator/dependencies/pom.xml
+++ b/src/main/resources/generator/dependencies/pom.xml
@@ -54,7 +54,7 @@
     <jqwik.version>1.9.0</jqwik.version>
     <!-- Maven Plugins -->
     <os-maven-plugin.version>1.7.1</os-maven-plugin.version>
-    <protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
+    <protobuf-maven-plugin.version>2.4.0</protobuf-maven-plugin.version>
     <maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
     <maven-checkstyle-plugin.version>3.4.0</maven-checkstyle-plugin.version>
     <git-commit-id-plugin.version>9.0.1</git-commit-id-plugin.version>
@@ -320,7 +320,7 @@
         <version>${protobuf.version}</version>
       </dependency>
       <dependency>
-        <groupId>org.xolstice.maven.plugins</groupId>
+        <groupId>io.github.ascopes</groupId>
         <artifactId>protobuf-maven-plugin</artifactId>
         <version>${protobuf-maven-plugin.version}</version>
       </dependency>


Test patch:
diff --git a/src/test/java/tech/jhipster/lite/generator/server/javatool/protobuf/domain/ProtobufModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/javatool/protobuf/domain/ProtobufModuleFactoryTest.java
index a23ce8c2f..781cba776 100644
--- a/src/test/java/tech/jhipster/lite/generator/server/javatool/protobuf/domain/ProtobufModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/server/javatool/protobuf/domain/ProtobufModuleFactoryTest.java
@@ -62,18 +62,22 @@ class ProtobufModuleFactoryTest {
         .containing(
           """
                   <plugin>
-                    <groupId>org.xolstice.maven.plugins</groupId>
+                    <groupId>io.github.ascopes</groupId>
                     <artifactId>protobuf-maven-plugin</artifactId>
                     <version>${protobuf-maven-plugin.version}</version>
                     <executions>
                       <execution>
                         <goals>
-                          <goal>compile</goal>
+                          <goal>generate</goal>
                         </goals>
                       </execution>
                     </executions>
                     <configuration>
-                      <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
+                      <protocVersion>${protobuf.version}</protocVersion>
+                      <sourceDirectories>
+                        <sourceDirectory>src/main/proto</sourceDirectory>
+                      </sourceDirectories>
+                      <failOnMissingSources>false</failOnMissingSources>
                     </configuration>
                   </plugin>
           """
@@ -81,21 +85,10 @@ class ProtobufModuleFactoryTest {
         .containing(
           """
                 <plugin>
-                  <groupId>org.xolstice.maven.plugins</groupId>
+                  <groupId>io.github.ascopes</groupId>
                   <artifactId>protobuf-maven-plugin</artifactId>
                 </plugin>
           """
-        )
-        .containing(
-          """
-              <extensions>
-                <extension>
-                  <groupId>kr.motd.maven</groupId>
-                  <artifactId>os-maven-plugin</artifactId>
-                  <version>${os-maven-plugin.version}</version>
-                </extension>
-              </extensions>
-          """
         );
     }
 
@@ -175,6 +168,17 @@ class ProtobufModuleFactoryTest {
                 </plugin>
           """
         )
+        .containing(
+          """
+              <extensions>
+                <extension>
+                  <groupId>kr.motd.maven</groupId>
+                  <artifactId>os-maven-plugin</artifactId>
+                  <version>${os-maven-plugin.version}</version>
+                </extension>
+              </extensions>
+          """
+        )
         .and()
         .hasFile("src/main/proto/proto.lock")
         .containing("{}");