9

There is a jar file with following structure:

/--
  |-dir1
   |-file1
   |-file2
   |-file3
  |-dir2
  |-dir3

I set filter to take files only from dir1

<includes>dir1/*</includes>

it successfully takes files only from that directory, but in target directory copied files are placed in dir1, how can remove path from files that are copied and leave there only name. So file1 will be copied to target/file1 and not to target/dir1/file1

<build>
        <finalName>${project.build.finalName}</finalName>
        <plugins>
            <plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>groupId</groupId>
                                    <artifactId>artifactId</artifactId>
                                    <version>version</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target/natives</outputDirectory>
                                    <includes>dir1/*</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
MaDa
  • 10,511
  • 9
  • 46
  • 84
michael nesterenko
  • 14,222
  • 25
  • 114
  • 182

2 Answers2

7

Support for the fileMappers tag was added in version 3.1.2 of the maven-dependency-plugin.

See official documentation Rewriting target path and file name

For example you could extract a nested .so file and place at a top level

<artifactItem>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>4.2.2</version>
    <includes>com/sun/jna/linux-x86/*.so</includes>
    <fileMappers>
        <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FlattenFileMapper"/>
    </fileMappers>
    <outputDirectory>${project.build.directory}/extracted-libs/</outputDirectory>
</artifactItem>
Adam
  • 35,919
  • 9
  • 100
  • 137
0

I don't know a way to do what you want. If I had your problem, I'd use the antrun plugin to rearrange, or I'd build a different artifact to pull from.

bmargulies
  • 97,814
  • 39
  • 186
  • 310