首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何停止maven-antrun-plugin运行测试

如何停止maven-antrun-plugin运行测试
EN

Stack Overflow用户
提问于 2012-04-20 20:17:56
回答 1查看 1.2K关注 0票数 0

编辑:解决了我在我的pom中配置了两次的问题。

我正在用maven建立一个产品配置文件。为了复制正确的production.properties文件并删除标准文件,我使用maven-antrun-plugin。

但是我不想运行任何测试。由于某些原因,这个插件试图运行一些canoo-web-test,这些测试不起作用(也不应该起作用,因为它们从未被使用过)。

关于如何让antrun插件只复制文件有什么想法吗?

以下是antrun代码:

代码语言:javascript
复制
                    <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <delete file="${project.build.outputDirectory}/properties/externalResources.properties"/>
                                    <delete file="${project.build.outputDirectory}/properties/externalResources.prod.properties"/>
                                    <copy file="src/main/resources/properties/externalResources.prod.properties"
                                          tofile="${project.build.outputDirectory}/properties/externalResources.properties"/>
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

下面是显示它试图做一些测试的错误:

代码语言:javascript
复制
[INFO] Executing tasks
[delete] Deleting: C:\xxx\target\classes\properties\externalResources.properties
[delete] Deleting: C:\xxx\target\classes\properties\externalResources.prod.properties
[copy] Copying 1 file to C:\xxx\target\classes\properties
Trying to override old definition of task retry
[echo] Testing 'XXX-1.2.0' with
[echo]                                                                     locale 'no'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

然后是一个堆栈跟踪,显示它试图读取web-tests.xml,由于该文件有错误,因此构建失败。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-21 17:39:51

听起来,您需要使用单个模块根据不同的配置创建不同的工件,这可以通过使用Maven的适当配置来实现。你可能会遇到这样的情况:

代码语言:javascript
复制
.
|-- pom.xml
`-- src
    |-- main
    |   |-- java
    |   |-- resources
    |   |-- environment
    |   |   |-- test
    |   |   |   `-- database.properties
    |   |   |-- qa
    |   |   |   `-- database.properties
    |   |   `-- production
    |   |       `-- database.properties
    |   `-- webapp

这是一个web应用程序的例子,但也适用于任何工件,如jar、ear等。此外,您还需要在pom中配置不同的区域:

代码语言:javascript
复制
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
      <execution>
        <id>test</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <descriptors>
            <descriptor>${project.basedir}/src/main/assembly/test.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
      <execution>
        <id>qa</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <descriptors>
            <descriptor>${project.basedir}/src/main/assembly/qa.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
      <execution>
        <id>production</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <descriptors>
            <descriptor>${project.basedir}/src/main/assembly/production.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
    </executions>
  </plugin>

而每个描述符都包含相应的文件夹:

代码语言:javascript
复制
 <id>test</id>
  <formats>
    <format>war</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <unpack>true</unpack>
      <useProjectArtifact>true</useProjectArtifact>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <outputDirectory>WEB-INF</outputDirectory>
      <directory>${basedir}/src/main/environment/test/</directory>
      <includes>
        <include>**</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>

这将导致maven mvn clean包的简单运行,并将为每个环境生成不同的工件(带有分类器)。详细的解释可以在here上找到。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10246101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档