编辑:解决了我在我的pom中配置了两次的问题。
我正在用maven建立一个产品配置文件。为了复制正确的production.properties文件并删除标准文件,我使用maven-antrun-plugin。
但是我不想运行任何测试。由于某些原因,这个插件试图运行一些canoo-web-test,这些测试不起作用(也不应该起作用,因为它们从未被使用过)。
关于如何让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,由于该文件有错误,因此构建失败。
发布于 2012-04-21 17:39:51
听起来,您需要使用单个模块根据不同的配置创建不同的工件,这可以通过使用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上找到。
https://stackoverflow.com/questions/10246101
复制相似问题