Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 473
Art Licis Avatar asked Jun 22 '12 12:06

Art Licis


People also ask

What is file filtering in Maven Assembly?

Introduction File filtering is used to substitute variable fields from inside a file to their represented values. For the Assembly Plugin, and most Maven filtering procedures, these variables are enclosed between $ { and }. For example, before a file is filtered, it contains $ {project.artifactId}.

How to copy arbitrary files in Maven?

A generic way to copy arbitrary files is to utilize Maven Wagon transport abstraction. It can handle various destinations via protocols like file, HTTP, FTP, SCP or WebDAV. There are a few plugins that provide facilities to copy files through the use of Wagon. Most notable are: There is the deploy-file goal.

What files are included in a Maven archive?

By default, Maven generated archives include the META-INF/maven directory, which contains the pom.xml file used to build the archive, and a pom.properties file that includes some basic properties in a small, easier to read format.

What are the examples of Maven copy resources?

Here is example of Maven Copy Resources Example with from one location to another location, include files, exclude files. 1. Maven Copy Resource from one location to another location 2. Maven copy resource with exclude files 3. Maven copy resource with include files 4. Maven copy resource with include + exclude files Was this post helpful? 1.


2 Answers

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

like image 124
khmarbaise Avatar answered Sep 25 '22 15:09

khmarbaise


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.

like image 30
Art Licis Avatar answered Sep 25 '22 15:09

Art Licis