【问题标题】:replace default Maven lifecycle goals替换默认的 Maven 生命周期目标
【发布时间】:2011-09-25 00:16:48
【问题描述】:

当我在具有<packaging>war</packaging> 的项目中运行mvn deploy 时,我收到错误:

[错误] 无法在项目 store-service-impl 上执行目标 org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-deploy):部署失败:存储库元素未在在 distributionManagement 元素或 -DaltDeploymentRepository=id::layout::url 参数中的 POM

似乎默认情况下,deploy:deploy 目标绑定到 deploy 生命周期阶段。换句话说,当 deploy 生命周期阶段运行时,Maven 将尝试将生成的工件(在本例中为 .war 文件)部署到远程存储库。

就我而言,我想将战争部署到远程 Tomcat 实例而不是远程 Maven 存储库。我已将以下内容添加到pom.xml

       <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.1.1</version>
            <configuration>
                <container>
                    <containerId>tomcat6x</containerId>
                    <type>remote</type>
                </container>
                <!--
                <executions>
                    <execution>
                        <id>deploy-tomcat</id>
                        <phase>deploy</phase>
                        <goals>
                           <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
                -->
                <configuration>
                    <type>runtime</type>
                    <properties>
                        <cargo.remote.uri>http://10.60.60.60:8080/manager</cargo.remote.uri>
                        <cargo.remote.username>jack</cargo.remote.username>
                        <cargo.remote.password>secret</cargo.remote.password>
                    </properties>
                </configuration>
                <deployer>
                    <type>remote</type>
                </deployer>
            </configuration>
        </plugin>

当我运行 mvn cargo:deploy 时,这成功部署了 .war。但是,如果我随后通过取消注释 &lt;executions&gt; 元素将此目标绑定到 Maven 生命周期的 deploy 阶段,则会收到上述错误。

似乎cargo:deploy 目标已添加到绑定到deploy 阶段的目标中,但我想替换 绑定到deploydeploy:deploy 目标cargo:deploy 目标的生命周期阶段(默认),这可能吗?

【问题讨论】:

    标签: java tomcat maven-2


    【解决方案1】:

    您应该将 cargo 绑定到 pre-integration-test 而不是 deploy - 然后您的故障安全测试可以在 integration-test 阶段针对已部署的 war 文件运行。您将使用mvn verify 运行测试。

    【讨论】:

    • 我没有任何集成测试,所以这与我无关。如果我将 cargo 绑定到 pre-integration-test 阶段,那么当有人运行 mvn install 时将部署 .war。我只希望在有人运行 mvn deploy 时部署它。
    • 无意冒犯,但恕我直言,您误用了deploy 阶段。它与您想要做的名称相同,但它不是您想要的。它用于部署到 Maven 存储库。 mvn install 将 war 文件安装到本地计算机的 maven 存储库中,我相信你知道。我会调查使用 Jenkins 之类的东西在成功构建时部署到远程服务器。哦,还有一些集成测试;-)
    【解决方案2】:

    您可以在配置 cargo 之前尝试禁用部署插件:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.5</version>
        <configuration>
            <skip>true</skip>
        </configuration>
    </plugin>
    

    【讨论】:

      【解决方案3】:

      您可以在执行 id default-deploy 上使用 maven-deploy-plugin 禁用默认部署目标。旧帖,放在这里以防万一。

      <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.7</version>
          <executions>
              <execution>
                  <id>default-deploy</id>
                  <phase>none</phase>
              </execution>
          </executions>
      </plugin>
      

      【讨论】:

        猜你喜欢
        • 2013-05-28
        • 1970-01-01
        • 1970-01-01
        • 2016-08-02
        • 2013-02-21
        • 1970-01-01
        • 2014-04-18
        • 2020-07-20
        • 2011-12-23
        相关资源
        最近更新 更多