Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven-resources-plugin error using copy-resources goal: 'resources', 'outputDirectory' missing or invalid

I'm trying to use the maven-resources-plugin to do some filtering using the copy-resources goal, and ran into the following error:

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

To isolate the problem, I created a very simple pom.xml, copied pretty nearly verbatim from http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html, ran it, and got the same error.

I'm invoking it with

mvn resources:copy-resources

Any ideas? Here's the test 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>

like image 998
Andy Dennie Avatar asked Jun 06 '12 23:06

Andy Dennie


3 Answers

The main problem you had is that you are invoking the plugin goal directly using

mvn resources:copy-resources

which does not necessarily create the output directory. Instead call the correct Maven lifecycle phase.

mvn process-resources

For a complete list of the lifecycle phases just run the mvn command without anything..

In general it almost always better to invoke a lifecycle phase rather than a goal directly since it guarantees that any preconditions are met (e.g. cant compile test classes before the classes to be tested..).

like image 72
Manfred Moser Avatar answered Oct 10 '22 12:10

Manfred Moser


Check if @bmargulies answer works for you. You can refer to these examples.

In any case, you do not need to use <pluginManagement> to achieve this. <pluginManagement> is used in multi-module scenarios to facilitate inheritance of plugin configurations.

You need to move the configuration out of execution element. The following snippet works.

<?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>
like image 40
Raghuram Avatar answered Oct 10 '22 10:10

Raghuram


Just remove the executions and their configuration. Normally you might want to define resources in <build> > <resources> respectively <build> > <testResources> (see http://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html) directly not within the plugin config using the default lifecycle process-(test-)resources which is automatically hooked by copy-(test-)resources.. Yes, it's a bad example on their page!

like image 1
childno͡.de Avatar answered Oct 10 '22 12:10

childno͡.de