4

I'm trying to copy a folder or following structure with maven-resources-plugin:

  root
   |- .metadata
   |- Project
   \- .gitignore

Project directory and .gitignore files are copied, but .metadata directory is left out for some reason.

How do I copy all contents of root folder?

Here is configuration I tried:

  <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
    <executions>
      <execution>
        <id>copy-resources</id>
        <phase>validate</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}/aut-ws</outputDirectory>
          <useBuildFilters>false</useBuildFilters>
          <nonFilteredFileExtensions>
            <nonFilteredFileExtension>metadata</nonFilteredFileExtension>
          </nonFilteredFileExtensions>
          <resources>
            <resource>
              <directory>H:\rcptt\workspaces\root</directory>
            </resource>
          </resources>
        </configuration>
      </execution>
    </executions>
  </plugin>
Basilevs
  • 22,440
  • 15
  • 57
  • 102

4 Answers4

4

You're looking for the configuration parameter addDefaultExcludes. See the documentation page.

So your configuration section should look like the following:

    <configuration>
      <outputDirectory>${project.build.directory}/aut-ws</outputDirectory>
      <addDefaultExcludes>false</addDefaultExcludes>
      ...
      <resources>
        <resource>
          <directory>H:\rcptt\workspaces\root</directory>
        </resource>
      </resources>
    </configuration>
Elie Richa
  • 51
  • 4
3

If this was relating to the maven-assembly-plugin then I had this problem, and had to use the useDefaultExcludes property (recent versions of the plugin only); by default it is true and it needs to be set to false to include directories like .metadata. This doesn't seem to be applicable to maven-resources-plugin though, or it might just not be a documented property.

Matthew Wise
  • 2,639
  • 26
  • 23
1

My first fix attempt would be trying modifying the resources element.

<resources>
  <resource>
    <directory>H:\rcptt\workspaces\root</directory>
    <includes>
      <include>**/*</include>
      <include>**/.*</include>
    </includes>
  </resource>
</resources>

Also, if you comment out the <nonFilteredFileExtensions> element, does it work?


Edit to show full plugin configuration that works with Maven 3.2.2, Resources plugin 2.7, on both Windows 7 and RedHat Linux. Command for testing is mvn validate.

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals><goal>copy-resources</goal></goals>
      <configuration>
        <outputDirectory>${project.build.directory}/testing123</outputDirectory>
        <resources>
          <resource>
            <directory>${project.basedir}/src/main/resources</directory>
            <includes>
              <include>**/*</include>
              <include>**/.*</include>
            </includes>
          </resource>
        </resources>
      </configuration>
    </execution>
  </executions>
</plugin>
user944849
  • 14,524
  • 2
  • 61
  • 83
  • In my case its never empty – kdoteu Mar 24 '15 at 13:13
  • What version of Maven & the resources plugin? I'm using Maven 3.2.2 & resources plugin 2.7. I added a `.metadata-directory` folder including 1 file in a test project's `src/main/resources` dir. I added the resources element above, with directory `${project.basedir}/src/main/resources` to an execution of the `copy-resources` goal, bound to the validate phase. When I run `mvn validate` the entire directory gets copied including the dot file. This worked on both Win 7 and RedHat Linux. – user944849 Mar 24 '15 at 14:17
  • I use plugin version 2.5 and Maven 3.2.2 too. But I noticed i use the resource-option filtering=true, because I need variable-replacement in a file. Can you try your example with ${project.basedir}/src/main/resources **/* **/.* true – kdoteu Mar 25 '15 at 12:41
  • Worked for me with 2.7 of the plugin and filtering enabled as you asked. Then, I switched plugin version to 2.5 and it still works. I wonder if there isn't some other plugin execution in your build that is removing the files after they are copied. Instead of running your normal build (e.g. `mvn clean install`) try running just up to the phase that the `copy-resources` goal is bound to (e.g. `mvn generate-resources`). If the dir is there, then something after that phase is removing the dirs. Run with debug enabled to see what. – user944849 Mar 25 '15 at 17:41
0

Just add addDefaultExcludes as @Matthew Wise said.

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
        <addDefaultExcludes>false</addDefaultExcludes>
    </configuration>
</plugin>

By default files like .gitignore, .cvsignore etc. are excluded which means they will not being copied. If you need them for a particular reason you can do that by settings this to false.

Documentation: https://maven.apache.org/plugins/maven-resources-plugin/copy-resources-mojo.html#addDefaultExcludes

MariuszS
  • 30,646
  • 12
  • 114
  • 155