当前位置: 首页 > 知识库问答 >
问题:

maven-resources-plugin使用copy-resources目标时出错:“resources”、“outputDirectory”缺失或无效

孙成益
2023-03-14

我试图使用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个答案

卫成和
2023-03-14

只需删除执行及其配置。通常,您可能希望在中定义资源

燕鸿文
2023-03-14

检查@bmargulies answer是否适合您。你可以参考这些例子。

在任何情况下,您都不需要使用

您需要将配置移出执行元素。以下片段有效。

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

空英逸
2023-03-14

您遇到的主要问题是您直接使用调用插件目标

mvn resources:copy-resources

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

mvn process-resources

要获得生命周期阶段的完整列表,只需运行mvn命令,而无需执行任何操作。。

一般来说,调用一个生命周期阶段比直接调用一个目标更好,因为它保证任何先决条件都得到满足(例如,不能在要测试的类之前编译测试类..).

 类似资料:
  • 我正在将一个现有的项目(遗留)移到Maven。其结构如下: 我打算有两个不同的概况:生产和开发。在production profile中,/warmodule/src/main/resources/prod/index.jsp应该组装到views/war目录中。在开发概要文件中,/warmodule/src/main/resources/dev/index.jsp应该复制到views/war目录中

  • 有没有人知道怎么才能完全避免呢?它往往会中断相当耗时的构建:-/

  • Unused Resources Remover for Android Gradle Plugin that removes unused resources in Android projects. Features Easy to remove unused resources by simple gradle command Customize extra/exclude files co

  • 我对Maven声纳设置有问题。我需要在src/main/java和src/main/resources中包含我的所有项目文件,以便SonarQube将显示所有文件的结果,但排除src/main/resources/static/file中的一些文件。对于测试路径,它已经在src/test/java中默认设置 但是当我用命令提示符运行我的maven-sonar时:mvn Sonar:Sonar。有这

  • By now you should have a good idea of how Jest can help you test your applications. If you're interested in learning more, here's some related stuff you might want to check out. 浏览文档 Learn about Snaps

  • To learn more about the Basic Elements To see the full API document in Markdown format, see APIs To contribute to Gio.js's code base, read Developer Guide