outputFileNameMapping and exclude problem with maven-assembly-plugin (3.1.0) - maven

I have a multi-module maven project with two separate "main" projects (projectA and projectB) from which I would like to build a zip file (incl. all dependencies).
One of the dependencies "subProjectC" I would like to exclude. This is the relevant portion of assembly.xml:
<moduleSets>
<moduleSet>
<!-- Enable access to all projects in the current multimodule build! -->
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>${project.groupId}:projectA</include>
<include>${project.groupId}:projectB</include>
</includes>
<excludes>
<exclude>${project.groupId}:subProjectC</exclude>
</excludes>
<binaries>
<outputFileNameMapping>${module.artifactId}.${module.extension}</outputFileNameMapping>
<outputDirectory>project-root/lib</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
subProjectC turns up in the zip file nevertheless.
Also, all dependencies show up with their full version, e.g. projectA-0.0.1-SNAPSHOT.jar, although the outputFileNameMapping should have prevented this...
What am I doing wrong?

Ok, it seems "outputFileNameMapping" only affects those artifacts that are specified in the "includes" list...

Related

Exclude all but some artifacts with Maven shade

Is there a way to create a fat jar with Maven that only contains some but not all dependency artifacts?
More concretely, I want to have two executions of shade: one that includes com.acme:* and one that includes all else. The point is to have two jars -- one with all my code and one with all the 3rd party deps. The latter is easy:
<artifactSet>
<excludes>
<exclude>com.acme:*</exclude>
</excludes>
</artifactSet>
But the former isn't. Because exclusions are processed after inclusions and everything is included by default, the following would not work:
<artifactSet>
<excludes>
<exclude>*:*</exclude>
</excludes>
<includes>
<include>com.acme:*</include>
</includes>
</artifactSet>
Any Maven mavens out there? (sorry but I had to)

maven assembly plugin : remove SNAPSHOT from dependency

The dependency jar added to the assembly zip has "SNAPSHOT" version added to its name. Is there a way to get only version number from ${artifact.baseVersion} without SNAPSHOT ?
This is run inside maven-assembly-plugin. I would like the dependency to output like parent-2.0.jar instead of parent-2.0-SNAPSHOT.jar.
assembly.xml
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>
<includes>
<include>www.example.com:parent:jar:2.0-SNAPSHOT</include>
</includes>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
There's a few methods of doing this depending on your pipeline. The maven versions plugin can be used,
http://www.mojohaus.org/versions-maven-plugin/set-mojo.html
http://www.mojohaus.org/versions-maven-plugin/set-mojo.html#removeSnapshot
A configuration like this would do it,
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<newVersion>${project.version}</newVersion>
<allowSnapshots>false</allowSnapshots>
</configuration>
</plugin>
I'd recommend wrapping it in a profile and activate it only when required. This will update the project.version with in the POM. You can then commit it back to the repo, leave it as is etc. etc.
You may also want to look at the build helper plugin which can handle regex-ing properties etc. if the versions plugin doesn't meet your needs.
http://www.mojohaus.org/build-helper-maven-plugin/usage.html#
I cannot find a simple solution. So I have added new property ${client-version} and used it in assmebly.xml.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<client-version>2.0</client-version>
</properties>
assembly.xml
<outputFileNameMapping>${artifact.artifactId}-${client-version}.${artifact.extension}</outputFileNameMapping>

maven assembly, avoiding full path in zip file?

I have a multi-module project which contains 2 modules (each with its own pom.xml) and a parent pom.xml pointing to those modules.
When I run "mvn clean package" on the parent pom, each project ends up with a zip file under it's own target folder. I would like to package a zip file containing each module zip file under the zip file's root folder but I am having some issues doing so.
I have created an assembly file in the parent pom.xml folder:
<!-- Release distribution -->
<assembly>
<id>release</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/projectA/target/</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.tar.gz</include>
</includes>
</fileSet>
<fileSet>
<directory>${basedir}/projectB/target/</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.tar.gz</include>
</includes>
</fileSet>
</fileSets>
</assembly>
While the above works, if we start adding more and more modules to this project, it gets very annoying to have to keep updating this assembly.
Ideally I'd like for it to automatically just go into every target folder for a module and get a zip file in there.
This can be accomplished by doing
...
<fileSet>
<directory>${basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/target/*.tar.gz</include>
</includes>
</fileSet>
however the issue here is the zip file will contain full paths, so rather than having zip files inside the root folder, the zip file will have projectA/target/xxxx.zip and projectB/target/xxxx.zip which is exactly what I do not want.
Is there any way to make a simple assembly in maven so I don't have to update it everytime I add a new module and not have full paths inside the zip?
EDIT 1
It looks like this is simply not possible. Either you get a nicely structured zip file with a hard to maintain assembly or you get an easy to maintain but annoingly structured zip file.
I'll leave this unanswered until I can find a proper solution
EDIT 2
Back at looking for a solution for this again. Regarding khmarbaise solution posted below there are a few issues with it:
- It relies on assemblies of dependencies, in my case I just want an assembly of assemblies (Which are more like fileSets and not dependencyset)
- The fact that it relies on me manually specifying which projects I want to have included in the assembly. I already have this information in the parent pom which specifies which modules should be built, so if I remove a module from the parent pom so that it is no longer built, the assembly should already know that and skip picking that project (Reason for which fileset seems to work so well except for the shitty, non-controllable path inside the assembly zip). I shouldnt have to manually mess with what modules I want included other than simply removing adding modules from the pom I am running the assembly from.
Has nobody really ever run into a similar problem?
First i would suggest to create dist-packaging module which contains the resulting package. Furthermore it sounds like your assembly-descriptor for creating the final archive which contains the zip files of others is wrong.
<id>proj1-assembly</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
But you must be aware that you have to maintain the dependencies in the dist-module as usual module dependencies like the following:
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>package-one</artifactId>
<version>${project.version}</version>
<classifier>package-1-assembly</classifier>
<type>zip</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>package-two</artifactId>
<version>${project.version}</version>
<classifier>package-2-assembly</classifier>
<type>zip</type>
</dependency>
....
Here you can find a full working example.
I just ran into the same problem: My resulting zip file contained the full system path! My original configuration looked like that:
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory>${project.build.directory}</outputDirectory>
<includes>
<include>someFolder/somefile.txt</include>
</includes>
</fileSet>
</fileSets>
As the result my zip file contained full system path!
After lots of investigating I found a working solution:
<fileSets>
<fileSet>
<outputDirectory>./</outputDirectory>
<directory>src/main/resources</directory>
<includes>
<include>someFolder/somefile.txt</include>
</includes>
</fileSet>
</fileSets>
So when specifying the outputDirectory with ${project.build.directory} then for some strange reason the full path will be part of the jar/zip file.

Maven Assembly: Introduce java doc from a separate project

I have an assembly descriptor to generate a separate package for our documentation, including the javadoc. It contains the following to include generated javadoc from the same project it's
running in (assembly is a subproject from core):
<fileSet>
<directory>../core/target/site/apidocs</directory>
<outputDirectory>javadoc</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
But how can I include java doc from a completely separate project which I do not know the path on the file system to, just have the .m2 repo let's say. I have tried the following but it does not seem to do anything:
<dependencySets>
<dependencySet>
<includes>
<include>com.company:company-utils:*:javadoc</include>
</includes>
<outputDirectory>apidocs-util</outputDirectory>
<unpack>true</unpack>
</dependencySet>
</dependencySets>
Any ideas appreciated.
Thanks
Jonas
Assuming the javadoc of the project that you are interested has been installed/deployed to local/remote repository, you can get it into your assembly by adding it as a dependency in your pom with javadoc as <classifier>.
<dependency>
<groupId>com.company</groupId>
<artifactId>company-utils</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>javadoc</classifier>
</dependency>
The following snippet in the assembly descriptor (without the classifier) worked for me.
<dependencySets>
<dependencySet>
<includes>
<include>com.company:company-utils</include>
</includes>
<outputDirectory>apidocs-util</outputDirectory>
<unpack>true</unpack>
</dependencySet>
</dependencySets>
Why would you like to create the javadoc within a different project than the current one. It is created during the default release cycle. So need to make a separate assembly for that. Or if you think you need something supplemental apart from the javadoc check the documentation for the maven-javadoc-plugin
BTW: Never make packaging from a different package than your own, cause that will produce trouble.

How can a build a jar with the maven assembly plugin that does not package any dependencies?

Maven assembly plugin has a predefined descriptor for jar-with-dependencies but not a jar-without-dependencies.
I know there is an exclusion config but wild cards do not seem to work with exclusions. Or I am not using them right.
<dependencySets>
<dependencySet>
<excludes>
<exclude>*</exclude>
</excludes>
</dependencySet>
</dependencySets>
You do not need to use assembly plugin, your scenario may be covered by maven-war-plugin with attachedClasses parameter and a classifier, see FAQ on site: http://maven.apache.org/plugins/maven-war-plugin/faq.html#attached

Resources