我正在maven中设置一个生产资料。要复制正确的production.properties文件并删除标准文件,我正在使用maven-antrun-plugin。
但我不想进行任何测试。由于某种原因,这个插件试图运行一些不起作用的canoo-web测试(并且因为它们从未被使用过而不应该工作)。
关于如何让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,并且由于该文件有错误,因此构建失败。
答案 0 :(得分:0)
听起来你需要有可能使用单个模块基于不同的配置创建不同的工件,这可以通过使用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找到。