【问题标题】:how to stop maven-antrun-plugin from running tests如何阻止 maven-antrun-plugin 运行测试
【发布时间】:2016-02-01 06:53:55
【问题描述】:

编辑:已解决 我在我的 pom 中配置了两次..

我正在 Maven 中设置生产配置文件。为了复制正确的 production.properties-files 并删除标准文件,我使用的是 maven-antrun-plugin。

但我不想运行任何测试。出于某种原因,这个插件试图运行一些不工作的 canoo-web-tests(并且不应该工作,因为它们从未被使用过)。

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

这是antrun代码:

                    <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>

这是显示它尝试进行一些测试的错误:

[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,并且由于该文件有错误,因此构建失败。

【问题讨论】:

标签: maven maven-antrun-plugin


【解决方案1】:

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

.
|-- pom.xml
`-- src
    |-- main
    |   |-- java
    |   |-- resources
    |   |-- environment
    |   |   |-- test
    |   |   |   `-- database.properties
    |   |   |-- qa
    |   |   |   `-- database.properties
    |   |   `-- production
    |   |       `-- database.properties
    |   `-- webapp

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

  <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>

而每个描述符都包含适当的文件夹:

 <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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多