使用copy-resources目标的maven-resources-plugin错误:'resources','outputDirectory'缺失或无效

时间:2012-06-06 23:56:55

标签: maven maven-resources-plugin

我正在尝试使用maven-resources-plugin使用copy-resources目标进行一些过滤,并遇到以下错误:

Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.5:copy-resources (default-cli) on project bar: The parameters 'resources', 'outputDirectory' for goal org.apache.maven.plugins:maven-resources-plugin:2.5:copy-resources are missing or invalid

为了隔离问题,我创建了一个非常简单的pom.xml,几乎从http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html逐字复制,运行它,并得到了同样的错误。

我用

调用它
mvn resources:copy-resources

有什么想法吗?这是测试pom.xml。

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>foo</groupId>
  <artifactId>bar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
              <resources>          
                <resource>
                  <directory>src/non-packaged-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

3 个答案:

答案 0 :(得分:30)

您遇到的主要问题是您使用

直接调用插件目标
mvn resources:copy-resources

不一定会创建输出目录。而是调用正确的Maven生命周期阶段。

mvn process-resources

有关生命周期阶段的完整列表,只需运行mvn命令即可。

通常,最好直接调用生命周期阶段而不是目标,因为它保证满足任何前提条件(例如,在要测试的类之前无法编译测试类)。

答案 1 :(得分:10)

检查@bmargulies答案是否适合您。您可以参考these examples

在任何情况下,您都不需要使用<pluginManagement>来实现此目的。 <pluginManagement>用于多模块方案,以促进plugin配置的继承。

您需要将configuration移出execution元素。以下代码段有效。

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>foo</groupId>
  <artifactId>bar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
          <resources>          
        <resource>
          <directory>src/non-packaged-resources</directory>
          <filtering>true</filtering>
        </resource>
          </resources>              
        </configuration>            
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

答案 2 :(得分:0)

只需删除执行及其配置即可。通常,您可能希望使用默认生命周期<build> > <resources>直接在插件配置中<build> > <testResources> process-(test-)resources copy-(test-)resources.(请参阅http://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html)定义资源,Dim num =123 Ex: Cells.Replace What:=Chr(Num), Replacement:=".", LookAt:= _ xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False 自动挂钩{{1} }}。 是的,这是他们网页上的一个不好的例子!

相关问题