2

How to unpack files from a sub-folder into a target folder?

Example:

My package includes ThisFolder and ThatFolder, I just want to unpack the folders and files from ThisFolder into the target directory, not the folder Thisfolder itself.

  <plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>unpack_this</id>
        <goals>
          <goal>unpack-dependencies</goal>
        </goals>
        <phase>initialize</phase>
        <configuration>
          <includeArtifactIds>ZipFile</includeArtifactIds>
          <includes>ThisFolder/**</includes>
          <stripVersion>true</stripVersion>
          <outputDirectory>${project.build.directory}/dependency</outputDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>

In this example I'm almost there, but ThisFolder is included. If I try to use:

<excludes>ThisFolder</excludes>

it just doesn't work. Is there a solution to do this?

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
Frankenstein
  • 653
  • 9
  • 18

1 Answers1

2

The Maven Dependency Plugin is made for dependencies, i.e. Java archives. The directory structure inside a Java archive is essential for the class files' package structure. So, it's easy to comprehed why the directories in your archive are considered by the plugin and cannot be suppressed.

The cleanest way I can think of at the moment is to copy the files afterwards. See Best practices for copying files with Maven.

(Another one is to use the Exec Maven Plugin with a zip.exe but that would introduce an external dependency.)

I'd prefer a solution with the Wagon Maven Plugin's copy goal as described in fnt's answer to the question linked above.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107