Maven Wagon插件:Can wagon:上传到多个位置?

Nic*_*uer 5 maven wagon maven-wagon-plugin

我正在研究Maven Wagon插件以尝试将一些工件上传到远程UNC服务器共享(\\servername\share\directory\to\put\to),并且我已将其配置为在POM中如此工作:

<build>
  <extensions>
    <extension>
      <groupId>org.apache.maven.wagon</groupId>
      <artifactId>wagon-file</artifactId>
      <version>1.0-beta-7</version>
    </extension>
  </extensions>
<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>wagon-maven-plugin</artifactId>
    <version>1.0-beta-3</version>
    <executions>
      <execution>
        <id>upload-jar-to-folder</id>
        <phase>deploy</phase>
        <goals>
          <goal>upload</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <fromDir>${project.build.directory}</fromDir>
      <includes>*</includes>
      <url>file://localhost///${servername}/${sharename}</url>
      <toDir>directory/to/put/artifact</toDir>
    </configuration>
  </plugin>
  ...
</build>
Run Code Online (Sandbox Code Playgroud)

当我传入时,这适用于一台服务器-Dservername=x -Dsharename=y,但是如何将其扩展,以便我可以为QA或Prod运行部署,我需要部署多台服务器?

我已经考虑(并编写)了一个mvn wagon:upload -Penvironment#多次运行的脚本- 每个服务器一次 - 但这对我来说似乎有瑕疵.如果我正在炮轰一个脚本来处理这个过程,我也可以编写整个部署的脚本.然而,这剥夺了Wagon(和Maven)的实用性......

有没有办法<executions>为一个目标运行多个?例如,wagon:upload在我刚运行时运行多个配置文件配置的任务mvn deploy -Pqa

Jan*_*Jan 4

如果您想使用多个配置文件,您只需使用:mvn deploy -Denv=qa并在此属性上触发一些配置文件,并在配置文件中定义服务器的配置。对于这种类型的配置文件激活请查看

http://maven.apache.org/guides/introduction/introduction-to-profiles.html

并搜索

-D环境=测试

下面是一个示例 POM,它在一个构建中执行两次 maven-antrun-plugin:

 <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>
  <groupId>org.stackoverflow</groupId>
  <artifactId>q5328617</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <profiles>
    <profile>
        <activation>
            <property>
                <name>env</name>
                <value>qa</value>
            </property>
        </activation>
        <id>qa1</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                      <execution>
                        <id>qa1</id>
                        <phase>test</phase>
                        <configuration>
                            <tasks>
                                <echo level="info">Executing qa1</echo>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                      </execution>
                    </executions>
                    <dependencies>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <activation>
            <property>
                <name>env</name>
                <value>qa</value>
            </property>
        </activation>
        <id>qa2</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                      <execution>
                        <id>qa2</id>
                        <phase>test</phase>
                        <configuration>
                            <tasks>
                                <echo level="info">Executing qa2</echo>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                      </execution>
                    </executions>
                    <dependencies>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>
  </profiles>
</project>
Run Code Online (Sandbox Code Playgroud)