Issue
I want to generate a zip file which contains:
- A fat jar
- Some other static .bat files
I tried to use maven-assembly-plugin
because it seems to be able to do that.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.company</groupId>
<artifactId>some-application</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>some-application</name>
<!-- ... -->
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-fat-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>my.company.some-application.SomeApplication</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
assembly.xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>data-initialization-batch</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>compileDataInit.bat</source>
</file>
<file>
<source>dataInit.bat</source>
</file>
</files>
<dependencySets>
<dependencySet>
<includes>
<include>my.company:some-application:jar:jar-with-dependencies</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
This generates the following warning:
[WARNING] The following patterns were never triggered in this artifact inclusion filter: o 'my.company:some-application:jar:jar-with-dependencies'
And the output zip file contains the bat files but no jar at all.
What makes me believe that this configuration should work is this sentence in the docs:
When the assembly is created it will use the assemblyId as the artifact's classifier and will attach the created assembly to the project so that it will be uploaded into the repository in the install and deploy phase.
Some more details:
- I have two executions because when I put one
descriptorRef
and onedescriptor
in the sameexecution
, they are apparently unordered and can't depend on each other - When I use
<include>my.company:some-application</include>
the regular jar gets properly included in the output zip, but I need the fat jar instead.
Solution
Ok I was just missing the useProjectAttachments
option which is described in the Assembly reference
Answered By - Guerric P
Answer Checked By - Gilberto Lyons (JavaFixing Admin)