具有配置文件的Maven Maven-Assembly-Plug构建 [英] Maven maven-assembly-plugin build with profile

查看:94
本文介绍了具有配置文件的Maven Maven-Assembly-Plug构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用maven-assembly-plugin构建一个轻便而又胖的Web应用程序,该应用程序以后将具有不同的内容.我以为我实际上可以使用两个配置文件mvn -Pliteweb,fatweb package,所以它将为每个配置文件创建两个构建程序集.但是当我运行它时,它实际上只创建了一个位于pom(liteweb)底部位置的程序集.

I am trying to use maven-assembly-plugin to build a lite and fat web application, the application will have different content later. I thought that I actually can use two profiles mvn -Pliteweb,fatweb package so it will create two build assembly for each profile. But when I run it, it actually only create one assembly that is in the bottom position in the pom ( the liteweb )

我已经尝试过一步一步地构建它了.我还检查了mvn help:active-profiles -P fatweb,liteweb,它正确显示了2个活动配置文件.

I already tried when I build it one by one its okay. I also check with mvn help:active-profiles -P fatweb,liteweb and it correctly show 2 active profile.

下面是我的测试pom(不包括此处的区别,我只希望它分别创建2个War文件和其他程序集文件).我在Maven还是个新手,所以我可能会误解这一点.是否可以从多个配置文件创建多个装配?

Below is my test pom ( its not including the difference in here, I just want it to create 2 War files and other assembly files separately ). I am still new at Maven so I might misunderstood this. Is creating multiple assembly from multiple profiles is possible to do?

<?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现在,我并没有放任何东西来确保一切正常.

fatassembly.xml for now I didnt put anything just to make sure everything work.

<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一样,我没有放任何东西来确保一切正常,但是我已经测试了里面的其他东西仍然无法正常工作.

liteassembly.xml same I didnt put anything to make sure everything work, but I already test with different thing inside still doesnt work.

<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)

And below is what happen when I execute mvn -Pfatweb,liteweb clean package seems like it building the same zip twice.. From same xml assembly, but actually from different execution ( exec1 and 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:\PROJECT\POMTEST\target
[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:\PROJECT\POMTEST\src\test\resources
[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:\PROJECT\POMTEST\target\LITEWEB-0.0.1]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\PROJECT\POMTEST\src\main\webapp]
[INFO] Webapp assembled in [27 msecs]
[INFO] Building war: D:\PROJECT\POMTEST\target\LITEWEB-0.0.1.war
[INFO] WEB-INF\web.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:\PROJECT\POMTEST\target\LITEWEB-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:\PROJECT\POMTEST\target\LITEWEB-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.我知道解决方法只是要两次构建的shellscript代码(如果每次正确运行时都构建一个配置文件),但是我只想使用特定于mvn的构建.

So the profile actually active, but after that the one that build in target folder is only the LITEWEB. If anyone know, please help me to understand why it not create both and why mvn like build the zip twice. I know the workaround is just shellscript code to build twice (if I build one profile each time it work correctly), but I want to use only mvn specific build.

下面是如果我执行mvn -Pfatweb,liteweb clean install时会发生的情况,两次创建了lib,但是它只构建了一次WAR文件.从日志中,我实际上意识到构建WAR的是战争插件,但是我如何使其在两个配置文件中都执行.?

Below is what happen if I do mvn -Pfatweb,liteweb clean install the lib were created twice, but it only build the WAR file once. From the log I actually realized the one that build the WAR is the war-plugin, but how do I make it execute for both profile..?

[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:\PROJECT\POMTEST\target
[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:\PROJECT\POMTEST\src\test\resources
[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:\PROJECT\POMTEST\target\LITEWEB-0.0.1]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\PROJECT\POMTEST\src\main\webapp]
[INFO] Webapp assembled in [26 msecs]
[INFO] Building war: D:\PROJECT\POMTEST\target\LITEWEB-0.0.1.war
[INFO] WEB-INF\web.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:\PROJECT\POMTEST\target\LITEWEB-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:\PROJECT\POMTEST\target\LITEWEB-0.0.1-lib-lite.zip
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ TEST_WEB ---
[INFO] Installing D:\PROJECT\POMTEST\target\LITEWEB-0.0.1.war to C:\Users\rm\.m2\repository\com\test\web\TEST_WEB\0.0.1\TEST_WEB-0.0.1.war
[INFO] Installing D:\PROJECT\POMTEST\pom.xml to C:\Users\rm\.m2\repository\com\test\web\TEST_WEB\0.0.1\TEST_WEB-0.0.1.pom
[INFO] Installing D:\PROJECT\POMTEST\target\LITEWEB-0.0.1-lib.zip to C:\Users\rm\.m2\repository\com\test\web\TEST_WEB\0.0.1\TEST_WEB-0.0.1-lib.zip
[INFO] Installing D:\PROJECT\POMTEST\target\LITEWEB-0.0.1-lib-lite.zip to C:\Users\rm\.m2\repository\com\test\web\TEST_WEB\0.0.1\TEST_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>部分 FROM 下的<plugin> TO 下的<execution>.对两个<configuration>部分都执行此操作.

In your POM move your <configuration> section FROM being under <plugin> TO being under <execution>. Do this for both <configuration> sections.

错误是您将插件配置了2次.当两个配置文件都处于活动状态时,maven会合并这两个配置,从而失去其中一个.

The error is that you configured the plugin 2 times. When both profiles are active, maven merges the 2 configurations, loosing one.

这篇关于具有配置文件的Maven Maven-Assembly-Plug构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆