0

to create a distribution I decided to use the maven assembly plugin. But in my case, I also need resources from other projects or simply artifacts. Let's use one simple example here and I'm confident that I can solve the more complex ones myself later.

We have a zip artifact on our local repository server which maven is configured to use. The zip file has a flat hierarchy and contains a native code wrapper, a jar file, README and example configurations. For the distribution package we want the first two. The wrapper should be placed in a bin/ directory, the jar file in a lib/ directory. But the zip file is only ever needed for the assembly step. I don't need it to compile or test. And reading the documentation on dependency scopes I didn't find a matching one for this particular use case. The other issues are described in the code below: When I don't specify the zip as a dependency I can't use the artifact later. And I can't place the unpacked files in the correct places.

Maybe my whole approach is wrong? I'd love to hear your opinions.

pom.xml

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
        <descriptors>
            <descriptor>src/assembly/dist.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <id>dist</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

dist.xml

 <dependencySets>
    <dependencySet>
        <includes>
            <!-- does only work when specified as a dependency in pom.xml -->
            <include>my:archive</include>
        </includes>
        <outputDirectory>unpacked</outputDirectory>
        <unpack>true</unpack>
        <unpackOptions>
            <includes>
                <include>wrapper</include>
                <include>extraLib.jar</include>
                <!-- can't move or rename -->
            </includes>
        </unpackOptions>
        <useProjectArtifact>false</useProjectArtifact>
    </dependencySet>
  </dependencySets>
a.ilchinger
  • 398
  • 4
  • 13

1 Answers1

0

I've done similar things a few times by using the maven-dependency-plugin directly instead of the maven-assembly plugin.

http://maven.apache.org/plugins/maven-dependency-plugin/unpack-mojo.html

Here's another SO question looking to do similar: Unzip dependency in maven

beirtipol
  • 823
  • 5
  • 21
  • That's certainly useful, but unfortunately I also don't see a possibility to rename and move the unpacked files. I could unpack it to a temporary directory and use the `` section in the assembly, but that seems rather hacky to me. – a.ilchinger Feb 02 '20 at 06:46
  • If you need the jar file for building, it might be appropriate to manually unpack it from the zip and place it in your local (or shared if in a team) repository and treat that as a normal dependency, then use the zip only for assembling – beirtipol Feb 03 '20 at 08:01