Maven Assembly - copy only file from subfolder when extracting from archive

I have a very specific requirement of our build infrastructure for copying some content of another JAR dependency to a specific subfolder of my web application. We use the maven-assembly-plugin, and the natural way to do this is to use <dependencySet>with <unpackOptions>.

Sample code (in assembly descriptor) I look like this:

    <dependencySet>
        <unpack>true</unpack>
        <scope>runtime</scope>
        <useProjectArtifact>false</useProjectArtifact>
        <includes>
            <include>my.group:artifact:jar</include>
        </includes>
        <unpackOptions>
            <includes>
                <include>subfolder/config.xml</include>
            </includes>
        </unpackOptions>
        <outputDirectory>WEB-INF/otherfolder</outputDirectory>
    </dependencySet>

The problem is that I cannot figure out how to indicate that I want to copy only one file artifact.jar/subfolder/config.xmlto the target WEB-INF/otherfolder. Actual result WEB-INF/otherfolder/subfolder/config.xml. As you can see, it is /subfolderadded to the final path. Is there a way to change the expression <include>so that it is /subfoldernot added?

Thanks in advance!

+5
3

, maven-assembly. , , Plexus, . Plexus, "" .

+2
+1

As @khmarbaise points out, the solution is to combine the dependency plugin with the build plugin:

  • At the beginning of the package phase, unzip the dependencies you need into a target directory
  • In a package (later in pom) use assembly to extract specific files from this directory into your artifact
0
source

All Articles