[英]Maven build lifecycle phase synchronization across modules
我有一個 maven 項目,其中有一個反應堆和幾個模塊,其中大部分都被打包為戰爭。 它們在 reactor / root pom.xml 中指定的順序定義了它們的構建順序。
pom.xml
....
<module>library1</module>
<module>library2</module>
<module>webapp1</module><!--war-->
<module>webapp2</module><!--war-->
<module>blackduck-scan</module><!-- create file to be placed into webapp2 post-build but pre-packaging of webapp2 -->
...
最后一個模塊,有意地,注定要在prepare-package
階段簡單地運行一個可執行文件。 更准確地說,是一個 blackduck 許可證掃描器,它本身最終會生成許可證通知文件,然后將該文件放入 web 應用程序之一的 /webapp 文件夾中,以便在部署后顯示。
這個想法是在編譯應用程序之后但在將這些應用程序打包為 WAR 工件之前放置此通知文件,以便將其包含在我們管道的當前交付中,而不是僅僅為了重新打包而重新構建。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<executable>java</executable>
<workingDirectory>.</workingDirectory>
<arguments>
<argument>-jar</argument>
<argument>synopsys-detect-8.4.0.jar</argument>
</arguments>
...
</configuration>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
我嘗試了兩種選擇來實現這一目標但沒有成功。
a) 將plugin/goal 添加到reactor pom.xml 會導致在target phase 為prepare-package
時首先執行goal,因此可能會在實際項目尚未構建時導致掃描結果不完整。
b) 如上所述將插件/目標添加為模塊將執行置於鏈的末尾,但是,webapps 的打包已經結束。
c) 第三種(可以說有效)但不太優雅的方法是將其分成兩個單獨的 maven 調用:
mvn clean install && mvn package
我看到模塊是按順序構建的,這是有充分理由的。 但是,是否有任何方法可以“同步”構建階段,以便僅在所有模塊的前一階段完成后才開始每個階段? 有效地簡單地調用,所有包括:
mvn clean install
我相信選擇是:
exploded
目標maven-assembly-plugin
打包目標war
maven-war-plugin
和maven-assembly-plugin
之間注入blackduck
的執行某事喜歡:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<!-- disabling building war -->
<id>default-war</id>
<phase>none</phase>
</execution>
<execution>
<id>exploded</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- blackduck execution here -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>war-assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
戰爭大會.xml:
<assembly>
<id>war</id>
<formats>
<format>war</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/${project.build.finalName}</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>/**/*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.