Maven-resources-plugin won't copy .metadata folder

丶灬走出姿态 提交于 2019-12-10 16:08:42

问题


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>

回答1:


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>



回答2:


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.




回答3:


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>



回答4:


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



来源:https://stackoverflow.com/questions/25422298/maven-resources-plugin-wont-copy-metadata-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!