Art Licis
Art Licis

Reputation: 3679

Maven Assembly - copy just file from sub-folder when extracting from archive

I have a very specific requirement of our build infrastructure to copy some contents of another JAR dependency to a specific sub-folder of my web-application. We're using maven-assembly-plugin, and a natural way to do this is to use <dependencySet> along with <unpackOptions>.

The code sample (in assembly descriptor) I have looks as following:

    <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 can't figure out how to specify that I only want to copy just a single file artifact.jar/subfolder/config.xml to a target WEB-INF/otherfolder. The actual result is WEB-INF/otherfolder/subfolder/config.xml. As you can see, /subfolder gets appended to a final path. Is there any way to change the <include> expression so that /subfolder doesn't get appended?

Thanks in advance!

Upvotes: 6

Views: 5699

Answers (4)

Radoslav Ivanov
Radoslav Ivanov

Reputation: 1072

Try this out with the <file/> tag and destName:

https://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_file

Upvotes: 0

Omri Spector
Omri Spector

Reputation: 2561

As @khmarbaise indicates, the solution lies in combining dependency-plugin with assembly-plugin:

  • On package phase start by unpacking the dependencies you need to some target directory
  • On package (later in pom) use assembly to extract specific files from that directory into your artifact

Upvotes: 1

Art Licis
Art Licis

Reputation: 3679

Browsing through source reveals that this is not possible via maven-assembly plug-in. It gets all includes that are specified in assembly descriptor, and then passes this information to Plexus archiver which is used through multiple stages. Include patterns are passed to Plexus archiver as well, and then it obviously performs 'unpack' conserving directory structure.

Upvotes: 2

khmarbaise
khmarbaise

Reputation: 97527

Have you ever thought about the maven-dependency-plugin which has a good support for unpacking archives.

Upvotes: 2

Related Questions