Home > Software design >  changing destination folder of resources in maven
changing destination folder of resources in maven

Time:12-27

I copied pasted the following snippet taken from the doc in my pom.xml

  <plugin>
    <!-- <groupId>org.apache.maven.plugins</groupId>-->
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.2.0</version>
    <executions>
      <execution>
        <id>copy-resources</id>
        <phase>validate</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/resources</outputDirectory>
          <resources>                                        
            <resource>
              <directory>${basedir}/template</directory>
              <filtering>true</filtering>
            </resource>             
          </resources>   
        </configuration>            
      </execution>
    </executions>
  </plugin>

but I get the following message when I try to trigger the deployment:

$ mvn resources:copy-resources 
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< org.test:myproject >------------------------
[INFO] Building myproject-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:copy-resources (default-cli) @ myproject ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.440 s
[INFO] Finished at: 2021-12-26T12:30:59 01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:copy-resources (default-cli) on project myproject: The parameters 'resources', 'outputDirectory' for goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:copy-resources are missing or invalid -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

here's my dir structures:

./resources
./template
./template/test.txt
./pom.xml

How can I change the destination folder of resources? why maven did not parse the configuration directives in the plugin?

CodePudding user response:

The full command syntax to execute a particular maven goal is :

mvn <plugin>:<goal>@<executionId>

When executionId is not specified , it is equal to default-cli by default.

Now you execute mvn resources:copy-resources which is equivalent to mvn resources:copy-resources@default-cli but your pom.xml does not defined this execution id for this goal. So it complains some parameters are missing and not configured well.

As you define the execution id to be copy-resources , which means you should execute :

mvn resources:copy-resources@copy-resources

Or as you bind this goal to the validate phase , that means you can also simply execute it by :

mvn validate
  • Related