Repository: jhipster/generator-jhipster
Pull request #9915 (2019-06-14 21:33:45)

Add new needle API to add a new annotation processor for Maven
-   Please make sure the below checklist is followed for Pull Requests.

-   [ ] [Travis tests](https://travis-ci.org/jhipster/generator-jhipster/pull_requests) are green
-   [x] Tests are added where necessary
-   [x] Documentation is added/updated where necessary
-   [x] Coding Rules & Commit Guidelines as per our [CONTRIBUTING.md document](https://github.com/jhipster/generator-jhipster/blob/master/CONTRIBUTING.md) are followed

<!--
Please also reference the issue number in a commit message to [automatically close the related Github issue](https://help.github.com/articles/closing-issues-via-commit-messages/)

Note: It is also possible to add `[skip ci]` to your commit message to skip Travis tests
-->



Patch:
diff --git a/generators/generator-base.js b/generators/generator-base.js
index d31b122dc4..c1bc760b3c 100644
--- a/generators/generator-base.js
+++ b/generators/generator-base.js
@@ -684,6 +684,17 @@ module.exports = class extends PrivateBase {
         this.needleApi.serverMaven.addPlugin(groupId, artifactId, version, other);
     }
 
+    /**
+     * Add a new annotation processor path to Maven compiler configuration.
+     *
+     * @param {string} groupId - plugin groupId
+     * @param {string} artifactId - plugin artifactId
+     * @param {string} version - explicit plugin version number
+     */
+    addMavenAnnotationProcessor(groupId, artifactId, version) {
+        this.needleApi.serverMaven.addAnnotationProcessor(groupId, artifactId, version);
+    }
+
     /**
      * Add a new Maven profile.
      *
diff --git a/generators/server/needle-api/needle-server-maven.js b/generators/server/needle-api/needle-server-maven.js
index 320baecd3a..8fa54fdad6 100644
--- a/generators/server/needle-api/needle-server-maven.js
+++ b/generators/server/needle-api/needle-server-maven.js
@@ -138,6 +138,22 @@ module.exports = class extends needleServer {
         this.addBlockContentToFile(rewriteFileModel, errorMessage);
     }
 
+    addAnnotationProcessor(groupId, artifactId, version) {
+        const errorMessage = `${chalk.yellow(
+            ' Reference to '
+        )}maven annotation processor (groupId: ${groupId}, artifactId:${artifactId}, version:${version})
+            ${chalk.yellow(' not added.\n')}`;
+        // prettier-ignore
+        const annotationProcessorPath = `${'<path>\n'
+            + '            <groupId>'}${groupId}</groupId>\n`
+            + `            <artifactId>${artifactId}</artifactId>\n`
+            + `            <version>${version}</version>\n`
+            + '        </path>';
+        const rewriteFileModel = this.generateFileModel(pomPath, 'jhipster-needle-maven-add-annotation-processor', annotationProcessorPath);
+
+        this.addBlockContentToFile(rewriteFileModel, errorMessage);
+    }
+
     addProfile(profileId, other) {
         const errorMessage = `${chalk.yellow('Reference to maven profile ')}
             (id: ${profileId})${chalk.yellow(' not added.\n')}`;
diff --git a/generators/server/templates/pom.xml.ejs b/generators/server/templates/pom.xml.ejs
index b2e2724e90..95e1435489 100644
--- a/generators/server/templates/pom.xml.ejs
+++ b/generators/server/templates/pom.xml.ejs
@@ -782,6 +782,7 @@
                             <version>${jaxb-runtime.version}</version>
                         </path>
 <%_ } _%>
+                        <!-- jhipster-needle-maven-add-annotation-processor -->
                     </annotationProcessorPaths>
                 </configuration>
             </plugin>


Test patch:
diff --git a/test/needle-api/needle-server-maven.spec.js b/test/needle-api/needle-server-maven.spec.js
index aa3e002025..5488ed8568 100644
--- a/test/needle-api/needle-server-maven.spec.js
+++ b/test/needle-api/needle-server-maven.spec.js
@@ -90,6 +90,11 @@ const mockBlueprintSubGen = class extends ServerGenerator {
                         '                </exclusion>\n' +
                         '            </exclusions>'
                 );
+                this.addMavenAnnotationProcessor(
+                    'annotationProcessorGroupId',
+                    'annotationProcessorArtifactId',
+                    'annotationProcessorVersion'
+                );
                 this.addMavenProfile('profileId', '            <other>other</other>');
             }
         };
@@ -221,6 +226,17 @@ describe('needle API server maven: JHipster server generator with blueprint', ()
                 );
             });
 
+            it('Assert pom.xml has the annotation processor added', () => {
+                assert.fileContent(
+                    'pom.xml',
+                    '        <path>\n' +
+                        '            <groupId>annotationProcessorGroupId</groupId>\n' +
+                        '            <artifactId>annotationProcessorArtifactId</artifactId>\n' +
+                        '            <version>annotationProcessorVersion</version>\n' +
+                        '        </path>'
+                );
+            });
+
             it('Assert pom.xml has the profile added', () => {
                 assert.fileContent(
                     'pom.xml',