copy the content of a directory of maven module project into another module - maven

I want to copy the content of a directorymodule maven project.
Here is the hierarchy
I want to copy the content of dist directory into Tourism/Tourism-Services/src/main/webapp directory
For this purpose, I tried to use maven-assembly-plugin
here is the extract of the relative pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>./</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>cfg-main-resources</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/angular5/tourism/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
Here is the extract of assembly.xml file
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>distribution</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory>./</outputDirectory>
<directory>src/main/angular5/tourism/dist</directory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
The problem is that the content of dist directory is copied in Tourism/Tourism-Web/target directory. I would like to copy this content in another module, in Tourism/Tourism-Services/src/main/weapp directory. Thank you for your help

I succeded in configuring the pom.xml's
Here is an extract of pom.xml within Tourism-Web sub-module
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>cfg-main-resources</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/angular5/tourism/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
Here is an extract of assembly descriptor file
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>assembly</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory>./</outputDirectory>
<directory>src/main/angular5/tourism/dist</directory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
Here is an extract of pom.xml of Tourism-Services sub-module
<dependencies>
<dependency>
<groupId>tourism-guide</groupId>
<artifactId>tourism-web</artifactId>
<version>${project.version}</version>
<classifier>assembly</classifier>
<type>zip</type>
<scope>compile</scope>
</dependency>
..................
's..................
</dependencies>
<build>
<!-- Set the name of the war, used as the context root when the app is
deployed -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-angular-dist-resources</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>compile</phase>
<configuration>
<outputDirectory>${basedir}/src/main/webapp</outputDirectory>
<includeArtifactIds>tourism-web</includeArtifactIds>
<includeGroupIds>${project.groupId}</includeGroupIds>
<excludeTransitive>true</excludeTransitive>
<excludeTypes>pom</excludeTypes>
<scope>compile</scope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Thank you for reading

Related

Spring boot pom.xml set up with assembly descriptors

I have created Spring boot application and now we want to deploy it to linux server.
Process is we create zip file of jar and then unzip it on server.
my pom.xml build set up is as follows:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.2.RELEASE</version>
<configuration>
<mainClass>com.csg.fid.emg.xray.eureka.server.EurekaServer</mainClass>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
For other applications which are not Spring boot application pom.xml build set up is as follows:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assemblies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>../src/main/assembly/bin-assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
Now i want to include descriptor tag in build configuration of Spring boot app, which is not supported in configuration section of Spring boot app.
How can this be achieved?
My bin-assembly.xml looks like this:
<assembly
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
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>bin</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>../src/main/assembly/include</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>

Package provided dependencies in a single zip file

I have put dependency jars in separate folder but expecting folder should be zipped instead of direct folder. I tried using assembly descriptor but it is creating separate folder with dependencies but not zipping it (folder should not be there, only zip file is expected). Please suggest me better approach to accommodate my dependency jars in a single zip file
pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>provided</includeScope>
<outputDirectory>/Users/venugopal/Documents/providedDependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/assembly/archive_format.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- append to the packaging phase. -->
<goals>
<goal>single</goal> <!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
archive_format.xml (Assembly descriptor
<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>bin</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>/Users/vp/Documents/providedDependencies</directory>
</fileSet>
</fileSets>
</assembly>
If I understand your requirement right, you want to package all provided dependencies into a zip file.
You are headed the wrong way using maven-dependency-plugin. You should use maven-assembly-plugin and its dependencySet:
<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>bin</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
<scope>provided</scope>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
</assembly>
Setting the scope to provided will make sure only the provided dependencies are considered in this set. We need to exclude the project artifact, otherwise it will be included by default.

Maven Assembly Create Custom Format

As part of a bigger project, I want to package some items I download together with some jar files as a .tar.gz package. And I did that successfully.
But now I want to "rename" that .tar.gz to something custom (e.a. to mypackage.banana)
Is there an easy way to achieve this?
What I have so far id accomplished using https://github.com/maven-download-plugin/maven-download-plugin
<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>${some.jar.file.url}</url>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<url>${some.models.zip.url}</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/data</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version> <!-- Old -->
<executions>
<execution> <!-- Build tar.gz archive. -->
<id>tar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/tar.xml</descriptor>
</descriptors>
<finalName>project-${project.version}-el6</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution> <!-- /NewStuff -->
</executions>
</plugin>
</plugins>
</build>
using tar.xml:
<assembly>
<id>tar</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>target/data</directory>
<outputDirectory>/data</outputDirectory>
</fileSet>
<fileSet>
<directory>target/lib</directory>
<outputDirectory>/lib</outputDirectory>
</fileSet>
<fileSet>
<directory>meta</directory>
<outputDirectory>/meta</outputDirectory>
</fileSet>
</fileSets>

Maven doesn't attach non-archived files with mavenAssemblyPlugin

I have some list of files (.jil).
I'd like to attach them to the build using maven-assembly-plugin.
I have no difficulty deploying these with the "zip"
format.
However, the "dir" format throw an exception:
[WARNING] Assembly file: C:\Branches\project-branch\target\project\output\directory is not a regular file (it may be a directory). It cannot be attached to the project build for installation or deployment.
pom file:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>make-devq</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>
${basedir}/environments/dev/assembly/descriptor.xml
</descriptor>
</descriptors>
<finalName>project</finalName>
<appendAssemblyId>true</appendAssemblyId>
<workDirectory>
${project.build.directory}/${project.artifactId}/work/project
</workDirectory>
<outputDirectory>
${project.build.directory}/${project.artifactId}/output
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
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>project-id</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/environments/dev/jils/</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jil</include>
</includes>
</fileSet>
</fileSets>
</assembly>
To add separate files you should use the build-helper-maven-plugin which offers such options to you.
<project>
...
<build>
<plugins>
<plugin>
<!-- add configuration for antrun or another plugin here -->
</plugin>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>some file</file>
<type>extension of your file </type>
<classifier>optional</classifier>
</artifact>
...
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
With the dir format you can't attach these files to your project.
BTW: The current up-to-date version of maven-assembly-plugin is 2.4.
According to Maven doc, the accepted formats are:
dir - Creates a directory zip
Creates a ZIP file format tar
Creates a TAR format tar.gz
Creates a gzip'd TAR format tar.bz2
Creates a bzip'd TAR format

multiple assemble results

I need to keep a status created during an artifact proceeding. So I've got the idea to bundle these state into an own zip and unpacking it in the prepare phase. Additional shall be the real result deployed as well. This result is a bundle to created files, valuable within a next artifact.
I'm trying create two result zips, but during deploy the second assembly name is ignored and always myArtifact-version.zip is deployed.
Whats wrong?
Thanks in advance,
Sven
my pom looks like:
<project ...>
<artifactId>myArtifact</artifactId>
<groupId>de.myGroup</groupId>
<packaging>pom</packaging>
...
<dependencies>
<dependency>
<groupId>de.myGroup</groupId>
<artifactId>gen-status</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/config</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
... proceeding generation
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>results</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assemble/bundle-gen-results.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>status</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<configuration>
<descriptors>
<descriptor>src/assemble/bundle-gen-status.xml</descriptor>
</descriptors>
<finalName>gen-status-${project.version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
</build>
</project>
The assemblies are:
gen-results.xml:
<assembly ... >
<id></id>
<formats><format>zip</format></formats>
<baseDirectory></baseDirectory>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/export</directory>
<includes>
<include>something.*/**/*.*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
bundle-gen-status.xml
<assembly ... >
<id></id>
<formats><format>zip</format></formats>
<baseDirectory></baseDirectory>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/config</directory>
<includes>
<include>status.file</include>
</includes>
<outputDirectory>classes/scripts</outputDirectory>
</fileSet>
</fileSets>
</assembly>
You can use the attach-artifact goal of build helper maven plugin to achieve this.
This allows me attaching the status file only to the current artifact. But then I'm getting a dependency cycle, when trying to add the status artifact.
<project ...>
<artifactId>myArtifact</artifactId>
<groupId>de.myGroup</groupId>
<packaging>pom</packaging>
...
<dependencies>
<dependency>
<groupId>de.myGroup</groupId>
<artifactId>myArtifact</artifactId>
<classifier>status</classifier>
<version>${project.version}</version>
</dependency>
</dependencies>
...
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/config</outputDirectory>
<includeClassifiers>status</includeClassifiers>
</configuration>
</execution>
</executions>
</plugin>
...
exec
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>status</id>
<phase>package</phase>
<goals><goal>attach-artifact</goal></goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/config/status.file</file>
<type>file</type>
<classifier>status</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>

Resources