I have multi module Project and each module has different configuration folders. Now I want to create zip files based configuration folder using maven and assembly.
Project
|
---module 1
| |
| ---dir 1
| |
| ---dir 2
| |
| ---dir3
| |
| ---src
|
---module 2
|
---dir 1
|
---dir 2
|
---src
My requirement is to create zip files based on directory names. Project has more than 50 modules and each module has different directory names.
Please suggest.
adding child pom.xml
<build>
<plugins>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<executions>
<execution>
<id>collective-package</id>
<configuration>
<items>
<item>dir 1</item>
<item>dir 2</item>
<item>dir 3</item>
</items>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<testSourceDirectory>test-integration-src</testSourceDirectory>
</build>
parent pom.xml
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<version>0.5.0</version>
<executions>
<execution>
<id>collective-package</id>
<phase>package</phase>
<goals>
<goal>iterator</goal>
</goals>
<configuration>
<pluginExecutors>
<pluginExecutor>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<configuration>
<descriptors>
<descriptor>assembly/zip_assembly.xml</descriptor>
</descriptors>
<finalName>#item#</finalName>
</configuration>
<goal>single</goal>
</pluginExecutor>
</pluginExecutors>
</configuration>
</execution>
</executions>
</plugin>
zip_assembly.xml
<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>${project.version}</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>tar.gz</format>
</formats>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.test:*</include>
</includes>
<sources>
<excludeSubModuleDirectories>false</excludeSubModuleDirectories>
<fileSets>
<fileSet>
<directory>${project.basedir}/target/classes</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>*</include>
</includes>
<excludes>
<exclude>com</exclude>
<exclude>schema</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.basedir}/../modulex/conf</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/../modulex/scripts</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/conf/<need here #item#></directory> <!--need directory name from parent/child pom.xml . sothat it picks the files from dir x-->
<outputDirectory>conf</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/../core/scripts</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/target</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
<excludes>
<exclude>*-tests.jar</exclude>
</excludes>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>
I can create zip for each directory but can't include files under dir x into zip. because I cant get dir name at runtime in zip_assembly.xml
how can we pass value of #item# to zip_assembly.xml files
Found solution. Used maven-antrun-plugin instead of maven-assembly-plugin
Related
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-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.
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>
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>
I am using Eclipse/maven plugin.
I want to delete external file with aboslute path, i have following example but it claims to delete only relative files which resides inside the project
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>some/relative/path</directory>
<includes>
<include>**/*.tmp</include>
<include>**/*.log</include>
</includes>
<excludes>
<exclude>**/important.log</exclude>
<exclude>**/another-important.log</exclude>
</excludes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<followSymLinks>false</followSymLinks>
<filesets>
<fileset>
<directory>D:\apache-tomcat-6.0.24\webapps\cat360-web-1.0.0</directory>
</fileset>
</filesets>
</configuration>
</plugin>