maven-assembly-plugin creates zip with no files - maven

maven-assembly-plugin generate empty zip archive, but source folder is not empty.
Plugin config:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.my.group</groupId>
<artifactId>maven-assemblies</artifactId>
<version>${bigdata-assemblies.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>airflow-dags</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>airflow-dags-assembly</descriptorRef>
</descriptorRefs>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
My airflow-dags-assembly.xml:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>airflow-dags</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/airflow-dags</directory>
<outputDirectory>/</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
<fileSet>
<directory>target/main/airflow-dags</directory>
<outputDirectory>/</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
</assembly>
I have files in src/main/airflow-dags and in target/main/airflow-dags, but I keep getting empty zip file:

Try adding includes to the fileSets as described in the assembly documentation.
<fileSet>
<directory>src/main/airflow-dags</directory>
<outputDirectory>/</outputDirectory>
<fileMode>0644</fileMode>
<includes>
<include>**/*</include>
</includes>
</fileSet>
Adjust the file pattern as needed.

Related

maven assembly plugin war packaging unexpected output result

I tried using the maven war plugin but is very opinionated on the folder structure and I need specific files into specific folders, so I've looked into using maven assembly plugin with the war format set.
Here's a snippet of the pom.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/war-assembly.xml</descriptor>
</descriptors>
<finalName>${project.artifactId}-assembly</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
and the war-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>war</id>
<formats>
<format>war</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>webapp/WEB-INF/lib</outputDirectory>
<excludes>
<exclude>*:war</exclude>
</excludes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}/${project.artifactId}/WEB-INF</directory>
<outputDirectory>webapp</outputDirectory>
<includes>
<include>/**/*</include>
</includes>
<excludes>
<exclude>webapp/lib</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/${project.artifactId}</directory>
<outputDirectory>webapp</outputDirectory>
<includes>
<include>/**/*</include>
</includes>
<excludes>
<exclude>WEB-INF</exclude>
<exclude>META-INF</exclude>
<exclude>info.xml</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<source>${project.build.directory}/${project.artifactId}/info.xml</source>
<filtered>true</filtered>
<outputDirectory></outputDirectory>
</file>
</files>
</assembly>
this produces the desired outcome in terms of where i need the files to be copied to, except something still packages lib folder, classes folder and the web.xml into the webapp folder, which I do not want.
Outputted directory structure:
Expected Directory Structure (lib, classes and web.xml) are removed because they are in the webapp/WEB-INF sub folder:
am I using the maven plugin incorrectly? or a setting that I am overseeing? Or a way to set the output directories for the classes, lib, and the web.xml?

maven include testOutputDirectory in the jar

Want to add the testoutputdirectory files in the project jar. Tried using below but, the test classes were not included in the jar
What need to be changed to include the same in the project jar?
Using below in the pom.xml
<build>
<finalName>${project.name}</finalName>
<testOutputDirectory>test/classes</testOutputDirectory>
<resources>
</resources>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>${final.name}</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<descriptor>./src/main/resources/assembly/assembly.xml</descriptor>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
.........
</build>
Below I have in the assembly.xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<moduleSets>
<moduleSet>
<sources>
<fileSets>
<fileSet>
<directory>.</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>test/classes/**/*.class</include>
</includes>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>
</assembly>
I dont think it is a good idea to do that at all. Maybe think about to create a separate test-jar. You can do it with the maven-jar-plugin test-jar goal
Nonetheless, if you really want to do that, you can achieve it by setting the
testOutputDirectory like:
<build>
<testOutputDirectory>${project.build.directory}/classes</testOutputDirectory>
</build>
The Tests.java are then compiled to target/classes and from there the maven-jar-plugin packages them to the jar.
Thank you all for your help.
I was able to include the testoutputdirectory to the jar using the below.
<build>
<finalName>${project.name}</finalName>
<testOutputDirectory>test/classes</testOutputDirectory>
<resources>
</resources>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>${final.name}</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/resources/assembly/assembly.xml</descriptor>
</descriptors>
<!-- descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs-->
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
.......
</plugins>
..........
</build>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>jar-with-dependencies</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>jar</format>
</formats>
<fileSets>
<fileSet>
<directory>./target/classes/</directory>
<outputDirectory></outputDirectory>
<includes>
<include>**/*.class</include>
</includes>
</fileSet>
<fileSet>
<directory>.</directory>
<outputDirectory></outputDirectory>
<includes>
<include>test/classes/**/*.class</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
</assembly>

Assembly ID is getting appended when zip file is created by maven

xml and pom.xml which creates jar file and then zip file with some artifacts including jar file. But when i run maven install zip file is getting created as GenerateMissingUsersReport-bin.zip instead I want it to create as GenerateMissingUsersReport.zip. I have set as false. But no difference.
Any pointers?
Here is dep.xml
<id>bin</id>
<baseDirectory>../</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/classes</directory>
<includes>
<include>plugin.xml</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
Here is pom.xml
<finalName>GenerateMissingUsersReport</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>GenerateMissingUsersReport</finalName>
<appendAssemblyID>false</appendAssemblyID>
<descriptor>src/assembly/dep.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>plugin.xml</exclude>
</excludes></configuration>
</plugin>
Add the following line under configurations element of the pom
<appendAssemblyId>false</appendAssemblyId>
Also make sure you use the latest version of the assembly plugin
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>

Maven package zip file structure

I package zip using maven-assembly-plugin. After finished package, the zip file structure as follow:
test.zip
|--test
|--test.jar
|--test.dalp
My assemble.xml and pom.xml configured as follow:
assemble.xml
<assembly>
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>/</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>test.dalp</include>
</includes>
</fileSet>
<fileSet>
<directory>/target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>test.jar</include>
</includes>
</fileSet>
</fileSets>
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
I want to know how to configure assemble.xml and pom.xml, and after I run "mvn clean package" in command line the zip file structure will be as follow:
test.zip
|__test.jar
|__test.dalp
You could change the configuration into the following:
<assembly>
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>/</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>test.dalp</include>
</includes>
</fileSet>
<fileSet>
<directory>/target</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>test.jar</include>
</includes>
</fileSet>
</fileSets>

Maven best practice for creating ad hoc zip artifact

Assume that I need to manage an artifact that consists of an aribtrary folder / file structure rolled up as a zip archive. It's not clear to me how to accomplish this in Maven in a way that best fits "the Maven way."
I know that there is no "zip" packaging type. Does this mean there is no generic lifecycle in Maven to simply take what I have in the resources folder, zip it up, and install/deploy it to my repositories?
I'm looking for options, with evaluations of how each option satisifies my requirement to follow the maven way, as I do not wish to incur the obvious penalities of straying from the golden path . . .
Decide what classifier you will use for your zip file, for sake of argument let's say it would be sample.
In your project create file assembly/sample.xml
Fill in assembly/sample.xml with something like this:
<?xml version="1.0" encoding="UTF-8"?>
<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>sample</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>some/directory/in/your/project</directory>
</fileSet>
</fileSets>
<!-- use this section if you want to package dependencies -->
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>*:pom</exclude>
</excludes>
<useStrictFiltering>true</useStrictFiltering>
<useProjectArtifact>false</useProjectArtifact>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
Add this to your pom's build section
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>create-distribution</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly/sample.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
As a result it should create and install you-project-name-VERSION-sample.zip.
I suggest you read chapter on assemblies from Sonatype's maven book:
https://books.sonatype.com/mvnref-book/reference/assemblies.html
Also, read assembly format specification: http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
Fill in assembly/sample.xml with something like this:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>install</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<includes>
<include>README*</include>
<include>*.sh</include>
</includes>
</fileSet>
<fileSet>
<directory>target/classes/</directory>
<outputDirectory>resources</outputDirectory>
<includes>
<include>*.properties</include>
<include>*.xml</include>
</includes>
<lineEnding>dos</lineEnding>
</fileSet>
<!--
<fileSet>
<directory>target/</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
<lineEnding>dos</lineEnding>
</fileSet>
-->
</fileSets>
<!-- use this section if you want to package dependencies -->
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>*:pom</exclude>
</excludes>
<useStrictFiltering>true</useStrictFiltering>
<useProjectArtifact>true</useProjectArtifact>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
add below codes in pom.xml file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>assembly/sample.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
run commands as mvn package -P dev -Dmaven.test.skip
will create the zip files that include :
xxxx.zip
-lib/.jar
-resources/.xml/properties
-readme
-start.sh
In your maven project create a folder assembly.
Add zip.xml file in the assembly folder.
Add below code in zip.xml to package the content of your project in to zip.
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>zip</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>directoryName of your project</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>

Resources