Maven Wagon 插件:wagon:upload 可以上传到多个位置吗?

发布于 2024-10-06 14:36:20 字数 1743 浏览 1 评论 0原文

我正在研究 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>

这对于一台服务器来说效果很好 当我传入 -Dservername=x -Dsharename=y 时,但是如何将其扩展,以便我可以在拥有多个服务器的情况下为 QA 或 Prod 运行部署部署到?

我考虑过(并编写了)一个脚本来多次运行 mvn wagon:upload -Penvironment# - 每个服务器一次 - 但这对我来说似乎有缺陷。如果我编写一个脚本来处理这个过程,我也可以编写整个部署的脚本。然而,这削弱了 Wagon(和 Maven)的实用性……

有没有一种方法可以为一个目标运行多个 ?例如,当我只运行 mvn deploy -Pqa 时,运行多个配置文件配置的 wagon:upload 任务?

I'm looking into the Maven Wagon Plugin to attempt uploading some artifacts to remote UNC Server shares (\\servername\share\directory\to\put\to), and I have gotten it configured to work like so in the 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>

This works great for one server when I pass in -Dservername=x -Dsharename=y, but how can I scale it out so I can run a deploy for QA or Prod where I have multiple servers to deploy to?

I've considered (and written) a script to run mvn wagon:upload -Penvironment# multiple times--once for each server--but this seems flawed to me. If I'm shelling out to a script to handle this process, I could just as well script out the entire deploy, too. However, this takes away from the usefulness of Wagon (and Maven)...

Is there a way to run multiple <executions> for one goal? For instance, running multiple profile configured wagon:upload tasks when I just run mvn deploy -Pqa?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2024-10-13 14:36:20

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

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

并搜索

-Denvironment=test

这是一个示例 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>

If you want to use multiple profiles you could just use: mvn deploy -Denv=qa and trigger some profiles on this property and define the configuration for your severs in the profiles. For this kind of profile activation look at

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

and search for

-Denvironment=test

Here's an example POM which does two executions of the maven-antrun-plugin in one build:

 <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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文