0

I've successfully used mvn -U dependency:copy-dependenciesto downloaded all dependencies - let's say module-a.jar, module-b.jar and module-c.jar.

Instead of having them in a flat directory, I need the jars in a certain hierarchical structure and also zipped.

release.zip
|
- base/classes/
|          |
|          - module-a.jar
|
- customer/
      |
      - classes/
      |    |
      |     - module-b.jar
      |
      |
      - plugins/
           |
           - module-c.jar     

There are 4 projects, the 3 modules above plus the project that aggregates all the modules in a certain version.

Is it possible to tell maven or the maven-dependency-plugin to copy the dependencies into the desired structure? How?

mike
  • 4,929
  • 4
  • 40
  • 80
  • What would be the logic for your special layout? (How to decide where to put each?) – Hugues M. Jun 14 '17 at 18:22
  • I would be happy, if I can solve this problem for a fixed mapping. The real project consists of over 30 jars. Other than that, there are some case, where elements with the same groupId have to be copied into the same folder, but this is not a rule, and also cases where a module x and all of its dependencies have to be copied in the same folder as x. – mike Jun 14 '17 at 18:28
  • 2
    Does it have to be the dependency plugin? You could use a plugin for copying each jar to the right directory and then another plugin for packaging the entire tree as a zip. https://maven.apache.org/plugins/maven-assembly-plugin/ is even better- it allows creating custom assembly descriptors. – vempo Jun 14 '17 at 19:56
  • No, it does not. I‘m happy with any maven solution. Thanks, I‘ll look into it! – mike Jun 14 '17 at 20:01
  • +1 for assembly plugin :) And if you really cannot get it to do exactly what you want (I doubt that, your need really looks like a good fit), you can always develop your own maven plugin. It's actually easy nowadays to get a hold of all project dependencies, and do whatever you want with them, [see this example](https://stackoverflow.com/a/42559904/6730571). – Hugues M. Jun 14 '17 at 20:08
  • Do I need an assembly descriptor for each output directory? – mike Jun 15 '17 at 09:15
  • The maven-assembly-plugin with an appropriate assembly descriptor will do that..You need a pom file defining the dependencies to the jar's and in the descriptor you can define the distribution into the different directories... – khmarbaise Jun 15 '17 at 09:57

1 Answers1

0

I used the maven assembly plugin with a custom assembly descriptor. In that descriptor I had to use one module set. Within that I could manage all the different destination directories (and their content) as dependencySets.

I had to setup a new project that contained all the jars I wanted to package as dependencys. In that same project I had to configure the maven assembly plugin referring to the assembly descriptor.

<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">
    <id>install</id>
    <includeBaseDirectory>false</includeBaseDirectory>

    <formats>
        <format>zip</format>
    </formats>

    <moduleSets>
        <moduleSet>

            <!-- Needed to have access to all projects in multi module build -->
            <useAllReactorProjects>true</useAllReactorProjects>

            <!-- If there is no include, every dependency (or at least more) are included -->
            <includes>
                <include>com.company:artifact_01</include>
            </includes>

            <binaries>
                <unpack>false</unpack>
                <outputDirectory>main/dir</outputDirectory>

                <dependencySets>

                    <dependencySet>
                        <includes>
                            <include>com.company:artifact_02</include>
                            <include>com.company:artifact_03</include>
                        </includes>
                        <outputDirectory>/main/dir</outputDirectory>
                    </dependencySet>

                    <dependencySet>
                        <includes>
                            <include>org.apache.felix:org.apache.felix.framework</include>
                        </includes>
                        <outputDirectory>/dir/felix</outputDirectory>
                    </dependencySet>

                    <dependencySet>
                        <includes>
                            <include>com.company:artifact_04</include>
                        </includes>
                        <outputDirectory>/dir/felix/plugin</outputDirectory>
                    </dependencySet>
            </binaries>
        </moduleSet>
    </moduleSets>

</assembly> 
mike
  • 4,929
  • 4
  • 40
  • 80