Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pack library and all its dependencies to one folder, but other dependencies in separate folder

I've maven project. I use maven-assembly-plugin to create zip files with all module dependencies packed in it. Need to create zip with following structure:

/my-libs
/other-libs

To my-libs need to pack dependencies from my-lib depenency + all its transitive dependencies. TO other-libs need to pack all other dependencies from current maven module.

Basically I need conditionally select target folder:

if (dependency in transitive-dependencies(my-lib))
   copy to /my-libs
else
   copy to /other-libs

Is it possible to do with maven-assembly-plugin ? Are there any alternative maven plugins to do so?

like image 567
turbanoff Avatar asked Feb 06 '19 15:02

turbanoff


People also ask

What is the use of Maven dependency plugin?

The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.

What is a maven assembly?

The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files. Your project can easily build distribution "assemblies" using one of the prefabricated assembly descriptors.


1 Answers

You need to define two dependencySet in the assembly XML file

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    ...                                                                                                                        
    <dependencySets>                                                                                                                         
        <dependencySet>                                                                                                                      
            <useProjectArtifact>false</useProjectArtifact>                                                                                   
            <useTransitiveFiltering>false</useTransitiveFiltering>                                                                            
            <includes>                                                                                                                       
                <include>com.example:dependency1:jar</include>                                                                       
                <include>com.example:dependency2:jar</include>                                                                       
                ...
            </includes>                                                                                                                      
            <outputDirectory>/my-libs</outputDirectory>                                                                                             
        </dependencySet>                                                                                                                     
        <dependencySet>                                                                                                                      
            <useProjectArtifact>false</useProjectArtifact>                                                                                   
            <useTransitiveFiltering>false</useTransitiveFiltering>                                                                            
            <includes>                                                                                                                       
                <include>com.example:other1:jar</include>                                                                       
                <include>com.example:other2:jar</include>                                                                       
                ...
            </includes>                                                                                                                      
            <outputDirectory>/other-libs</outputDirectory>                                                                                             
        </dependencySet>                                                                                                                     
    </dependencySets>         
    ...                                                                                                               
</assembly>   

Docs:

http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

like image 93
isalgueiro Avatar answered Oct 22 '22 22:10

isalgueiro