当我使用clean install post-site -Pdev
编译带有POM内容的项目时,我收到以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project test-copy: An Ant BuildException has occured:
Only one of tofile and todir may be set.
[ERROR] around Ant part ...<copy todir="temp/config" file="temp1/temp1.conf" tofile="temp2/temp.conf" failonerror="false">... @ 5:98 in Projects/TestCopy/test-copy/target/antrun/build-main.xml
如何解决此问题?
在编译期间生成的Ant脚本:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="maven-antrun-" default="main" >
<target name="main">
<echo>Base Dir:</echo>
<copy todir="temp/config" file="temp1/temp1.conf" tofile="temp2/temp.conf" failonerror="false">
<fileset file="/Users/Projects/TestCopy/test-copy/*.conf"/>
</copy>
</target>
</project>
POM内容:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>temp.test.copy</groupId>
<artifactId>test-copy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test-copy</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Base Dir1: </echo>
<copy todir="temp/config" failonerror="false">
<fileset file="${basedir}/*.conf"/>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>post-site</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Base Dir: </echo>
<copy file="temp1/temp1.conf"
tofile="temp2/temp.conf">
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
答案 0 :(得分:1)
问题是您的执行中缺少id
个标签。由于您没有定义ID,Maven将使用default
。现在,您的基本pom中的默认执行以及开发配置文件中的默认执行。
由于id是相同的,maven只是合并了poth定义,导致你得到了相当奇怪的混合蚂蚁。
所以只需将不同的 <id>
标签添加到机器人执行中,你就可以了。
附加说明:
你应该在执行中始终包含id,除了防止像你的问题这样的效果之外,他们还将服务器作为文档,因为在构建期间打印出id。因此,请选择有意义的内容,例如:copy-configuration-dir
和copy-single-config-to-site
。