Maven Maven汇编插件使用概要文件构建



我正在尝试使用maven汇编插件来构建一个lite和fat web应用程序,该应用程序稍后会有不同的内容。我认为我实际上可以使用两个配置文件mvn -Pliteweb,fatweb package,因此它将为每个配置文件创建两个构建组件。但当我运行它时,它实际上只创建了一个位于pom(liteweb)底部位置的程序集

我已经试过了,当我一个接一个地建造它的时候,没问题。我还检查了mvn help:active-profiles -P fatweb,liteweb,它正确地显示了2个活动配置文件。

下面是我的测试pom(它不包括这里的区别,我只想让它单独创建2个War文件和其他程序集文件)。我还是Maven的新手,所以我可能会误解这一点。是否可以从多个配置文件创建多个部件?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.web</groupId>
<artifactId>TEST_WEB</artifactId>
<packaging>war</packaging>
<name>WEB Application</name>
<version>0.0.1</version>
<properties>
<litewebPath>src/main/lite</litewebPath>
<fatwebPath>src/main</fatwebPath>
</properties>
<profiles>
<profile>
<id>fatweb</id>
<build>
<resources>
<resource>
<directory>${fatwebPath}/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<finalName>WEB-${project.version}</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptors>
<descriptor>fatassembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>exec1</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>liteweb</id>
<build>
<resources>
<resource>
<directory>${litewebPath}/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<finalName>LITEWEB-${project.version}</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptors>
<descriptor>liteassembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>exec2</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

fatassembly.xml目前我并没有为了确保一切正常工作而放任何东西。

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>lib</id>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
</dependencySet>
</dependencySets>
</assembly>

liteassembly.xml我没有放任何东西来确保一切正常,但我已经用里面的不同东西进行了测试,仍然不起作用。

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>lib-lite</id>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
</dependencySet>
</dependencySets>
</assembly>

执行mvn help:active-profiles -Pfatweb,liteweb

Active Profiles for Project 'com.test.web:TEST_WEB:war:0.0.1':
The following profiles are active:
- fatweb (source: com.test.web:TEST_WEB:0.0.1)
- liteweb (source: com.test.web:TEST_WEB:0.0.1)

下面是当我执行mvn-Pfatweb时发生的事情,liteweb clean包似乎构建了两次相同的zip。。来自相同的xml程序集,但实际上来自不同的执行(exec1和exec2)

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building WEB Application 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TEST_WEB ---
[INFO] Deleting D:PROJECTPOMTESTtarget
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ TEST_WEB ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ TEST_WEB ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ TEST_WEB ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:PROJECTPOMTESTsrctestresources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ TEST_WEB ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ TEST_WEB ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ TEST_WEB ---
[INFO] Packaging webapp
[INFO] Assembling webapp [TEST_WEB] in [D:PROJECTPOMTESTtargetLITEWEB-0.0.1]
[INFO] Processing war project
[INFO] Copying webapp resources [D:PROJECTPOMTESTsrcmainwebapp]
[INFO] Webapp assembled in [27 msecs]
[INFO] Building war: D:PROJECTPOMTESTtargetLITEWEB-0.0.1.war
[INFO] WEB-INFweb.xml already added, skipping
[INFO]
[INFO] --- maven-assembly-plugin:2.6:single (exec1) @ TEST_WEB ---
[INFO] Reading assembly descriptor: liteassembly.xml
[INFO] Building zip: D:PROJECTPOMTESTtargetLITEWEB-0.0.1-lib-lite.zip
[INFO]
[INFO] --- maven-assembly-plugin:2.6:single (exec2) @ TEST_WEB ---
[INFO] Reading assembly descriptor: liteassembly.xml
[INFO] Building zip: D:PROJECTPOMTESTtargetLITEWEB-0.0.1-lib-lite.zip
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.961 s
[INFO] Finished at: 2016-06-14T15:23:05+08:00
[INFO] Final Memory: 12M/229M
[INFO] ------------------------------------------------------------------------

所以配置文件实际上是活动的,但在那之后,在目标文件夹中构建的配置文件只是LITEWEB。如果有人知道,请帮助我理解为什么它不同时创建这两个,以及为什么mvn喜欢构建两次zip。我知道解决方法只是两次构建shell脚本代码(如果每次都能正确构建一个概要文件),但我只想使用mvn特定的构建。

以下是如果我执行mvn -Pfatweb,liteweb clean install,则会发生的情况。lib创建了两次,但它只构建了一次WAR文件。从日志中,我实际上意识到构建WAR的是WAR插件,但我如何使它对两个概要文件都执行。。?

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building WEB Application 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TEST_WEB ---
[INFO] Deleting D:PROJECTPOMTESTtarget
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ TEST_WEB ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ TEST_WEB ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ TEST_WEB ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:PROJECTPOMTESTsrctestresources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ TEST_WEB ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ TEST_WEB ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ TEST_WEB ---
[INFO] Packaging webapp
[INFO] Assembling webapp [TEST_WEB] in [D:PROJECTPOMTESTtargetLITEWEB-0.0.1]
[INFO] Processing war project
[INFO] Copying webapp resources [D:PROJECTPOMTESTsrcmainwebapp]
[INFO] Webapp assembled in [26 msecs]
[INFO] Building war: D:PROJECTPOMTESTtargetLITEWEB-0.0.1.war
[INFO] WEB-INFweb.xml already added, skipping
[INFO]
[INFO] --- maven-assembly-plugin:2.6:single (exec1) @ TEST_WEB ---
[INFO] Reading assembly descriptor: fatassembly.xml
[INFO] Building zip: D:PROJECTPOMTESTtargetLITEWEB-0.0.1-lib.zip
[INFO]
[INFO] --- maven-assembly-plugin:2.6:single (exec2) @ TEST_WEB ---
[INFO] Reading assembly descriptor: liteassembly.xml
[INFO] Building zip: D:PROJECTPOMTESTtargetLITEWEB-0.0.1-lib-lite.zip
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ TEST_WEB ---
[INFO] Installing D:PROJECTPOMTESTtargetLITEWEB-0.0.1.war to C:Usersrm.m2repositorycomtestwebTEST_WEB.0.1TEST_WEB-0.0.1.war
[INFO] Installing D:PROJECTPOMTESTpom.xml to C:Usersrm.m2repositorycomtestwebTEST_WEB.0.1TEST_WEB-0.0.1.pom
[INFO] Installing D:PROJECTPOMTESTtargetLITEWEB-0.0.1-lib.zip to C:Usersrm.m2repositorycomtestwebTEST_WEB.0.1TEST_WEB-0.0.1-lib.zip
[INFO] Installing D:PROJECTPOMTESTtargetLITEWEB-0.0.1-lib-lite.zip to C:Usersrm.m2repositorycomtestwebTEST_WEB.0.1TEST_WEB-0.0.1-lib-lite.zip
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.768 s
[INFO] Finished at: 2016-06-16T10:49:10+08:00
[INFO] Final Memory: 12M/174M
[INFO] ------------------------------------------------------------------------ 

在您的POM中,将您的<configuration>部分从位于<plugin>下方的移动到位于<execution>下方的。对两个<configuration>部分都执行此操作。

错误是您配置了2次插件。当两个配置文件都处于活动状态时,maven会合并这两个配置,丢失一个配置。

最新更新