Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I strip subdirectories when using maven dependency plugin

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>
like image 550
michael nesterenko Avatar asked Oct 23 '11 10:10

michael nesterenko


1 Answers

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>
like image 200
Adam Avatar answered Oct 09 '22 01:10

Adam