选择多个配置文件时不会部署wildfly-maven-plugin

时间:2017-04-03 21:49:47

标签: maven deployment wildfly

我正在使用POM.xml将WAR文件部署到Wildfly服务器,具体取决于环境安装的应用程序。我使用的项目有3个不同的应用程序,一个环境可以安装1到3个这样的应用程序。

因此,我已经为每个应用程序制作了配置文件 - 如果安装了应用程序A,请运行应用程序A配置文件以将A应用程序部署到服务器。如果安装了B,请运行应用程序B配置文件等

问题在于,当我使用多个应用程序(例如应用程序A和应用程序B)运行我的Maven构建时,它只会部署其中一个应用程序。如果我单独在每个配置文件上运行单独的Maven构建,它就可以很好地部署。我认为我的问题在于maven-wildfly-plugin本身,因为在运行多个配置文件时,它们在使用Maven help:active-profiles选项时显示为活动状态:

[INFO] 
Active Profiles for Project 'com.foo.bar:auto-deploy:pom:1.0.0-SNAPSHOT': 

The following profiles are active:

 - wildfly-deploy-a (source: com.foo.bar:auto-deploy:1.0.0-SNAPSHOT)
 - wildfly-deploy-b (source: com.foo.bar:auto-deploy:1.0.0-SNAPSHOT)

构建本身的输出如下:

[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Auto-Deploy Wildfly 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ auto-deploy ---
[INFO] Installing C:\..........\AutoDeploy\pom.xml to C:\.....\.m2\repository\com\foo\bar\auto-deploy\1.0.0-SNAPSHOT\auto-deploy-1.0.0-SNAPSHOT.pom
[INFO] 
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ auto-deploy ---
[INFO] Skipping artifact deployment
[INFO] 
[INFO] --- wildfly-maven-plugin:1.1.0.Alpha11:deploy-artifact (deploy-a) @ auto-deploy ---
Apr 03, 2017 5:31:52 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.1.Final
Apr 03, 2017 5:31:52 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.1.Final
Apr 03, 2017 5:31:53 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.9.Final
[INFO] Authenticating against security realm: ManagementRealm
[INFO] 
[INFO] --- wildfly-maven-plugin:1.1.0.Alpha11:deploy-artifact (deploy-b) @ auto-deploy ---
[INFO] Authenticating against security realm: ManagementRealm
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.615 s
[INFO] Finished at: 2017-04-03T17:32:06-04:00
[INFO] Final Memory: 20M/210M
[INFO] ------------------------------------------------------------------------

在这种情况下,deploy-adeploy-b配置文件似乎都会运行,但只有deploy-b的应用程序成功部署。我的POM.xml如下:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>auto-deploy</artifactId>
    <packaging>pom</packaging>
    <name>Auto-Deploy Wildfly</name>

    <parent>
        <groupId>com.foo.bar</groupId>
        <artifactId>parent-project</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <properties>
        <wildfly.deploy.version>1.0.2.Final</wildfly.deploy.version>
        <wildfly.hostname>localhost</wildfly.hostname>
        <wildfly.mgmt.native.port>9999</wildfly.mgmt.native.port>               
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.foo.bar</groupId>
            <artifactId>app-a</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>com.foo.bar</groupId>
            <artifactId>app-b</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>1.1.0.Alpha11</version>
                    <configuration>
                        <force>true</force>
                        <protocol>remote</protocol>
                        <hostname>${wildfly.hostname}</hostname>
                        <port>${wildfly.mgmt.native.port}</port>
                        <username>${wildfly.mgmt.username}</username>
                        <password>${wildfly.mgmt.password}</password>
                        <timeout>120</timeout>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>           
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>wildfly-deploy-a</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <configuration>
                            <groupId>com.foo.bar</groupId>
                            <artifactId>app-a</artifactId>
                            <skip>false</skip>
                        </configuration>
                        <executions>
                            <execution>
                                <id>deploy-a</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>deploy-artifact</goal>
                                </goals>
                            </execution>
                        ...
        </profile>
        <profile>
            <id>wildfly-deploy-b</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <configuration>
                            <groupId>com.foo.bar</groupId>
                            <artifactId>app-b</artifactId>
                            <skip>false</skip>
                        </configuration>
                        <executions>
                            <execution>
                                <id>deploy-b</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>deploy-artifact</goal>
                                </goals>
                            </execution>
                        ...
        </profile>  
    </profiles>
</project>

我正在使用mvn deploy -Pwildfly-deploy-a,wildfly-deploy-b执行它。我将配置文件传递给Maven的顺序似乎并不重要 - 它总是部署在POM中的最后一个配置文件中定义的应用程序(所以应用程序b)。我也尝试了mvn deploy -Pwildfly-deploy-a -Pwildfly-deploy-b,但这也不起作用。

我是否违反了Maven的一些最佳做法?我今天研究的所有内容都表明这应该有效,这就是为什么我有一个暗示插件导致这种行为的原因。

编辑 - 我还尝试通过让其中一个配置文件使用deploy目标而另一个使用deploy-artifact目标来混合它但我得到相同的行为。这可能是一些网络或线程问题吗?

编辑2 - 其他奇怪的行为:当两个配置文件都使用deploy目标而不是deploy-artifact时,这两个应用都不会部署...当使用deploy单独运行时,它们将部署正常。

1 个答案:

答案 0 :(得分:1)

您的插件配置无法合并;第二个将始终覆盖第一个。

诀窍是将配置移动到执行部分:

<profiles>
    <profile>
        <id>wildfly-deploy-a</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>deploy-a</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>deploy-artifact</goal>
                            </goals>
                            <configuration>
                                <groupId>com.foo.bar</groupId>
                                <artifactId>app-a</artifactId>
                                <skip>false</skip>
                            </configuration>
                        </execution>
                    ...
    </profile>
    <profile>
        <id>wildfly-deploy-b</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>deploy-b</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>deploy-artifact</goal>
                            </goals>
                            <configuration>
                                <groupId>com.foo.bar</groupId>
                                <artifactId>app-b</artifactId>
                                <skip>false</skip>
                            </configuration>
                        </execution>
                    ...
    </profile>  
</profiles>

现在每个执行都有它自己的配置。