Using <fileSets> with Maven assemblies - maven-2

I am trying to add specific directories from Maven modules into my build. I believe that fileSets are the way to go back this.
I would appreciate a clear and concise way of using fileSets to obtain necessary directories from Maven modules that just simply contain a directory with some necessary resources.

If you want to include entire modules, use moduleSets, but if you want to pick and choose which files to add you can use fileSets in an assembly config file from the top level project like this:
<fileSets>
<fileSet>
<directory>${basedir}/myModule/src/main/resources</directory>
<includes>
<include>*.txt</include>
</includes>
</fileSet>
</fileSets>

Related

Maven : How to move a file during assembly

During assemby, I want include all files from a release directory into the root of my assembly.
If I do the following:
<fileSet>
<directory>${basedir}/</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>src/main/resources/release/**</include>
</includes>
</fileSet>
Then all of the files get added to a folder named src/main/resources/release/ inside my release.
Is there a way to not include the folder path when including the fields?
I'm using the 2.3 version of the assembly plugin. If there is not a way to do this with the assembly plugin is there a way to do this with other plugins? (preferably without resorting to the ant plugin).
You have to do the configuration a little bit different like this:
<fileSet>
<directory>src/main/resources/release/</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**</include>
</includes>
</fileSet>

How do you include resources files in Maven site source cross reference?

Especially of interest are the configuration xml files that are so common.
I'd hope there was a configuration to the JXR plugin. I tried */.xml but that didn't work.
It looks like Maven JXR plugin does provide a way to include/exclude files though not sure if it is just .java files.
You should try **/*.xml rather than */*.xml
<includes>
<include>**/*.xml</include>
</includes>

Stranges files in my assembly since switching to <lineEnding>unix</lineEnding>

since I've inserted the option <lineEnding>unix</lineEnding> into my fileSets and files in my Maven assembly plugin configuration, strange files are placed in my tar.
They look as following:
ignore.me.1499711160.filtered.903528596.formatted
run.sh.2124782621.filtered.1130667884.formatted
Do you know why this occurrs?
This is a bug captured in MASSEMBLY-462. Either patch the plugin with the attached patch or revert to a previous version (try with 2.2-beta-4).
I had the same problem i used excludes tag in the assembler, you can use it in pom too:
<fileSet>
<directory>DEV</directory>
<outputDirectory>${file.separator}FileName${file.separator}DEV</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<lineEnding>unix</lineEnding>
<excludes>
<exclude>*.formatted</exclude>
</excludes>
</fileSet>

How to remove generated build artifacts from Maven's target directory?

How to remove generated build artifacts from Maven's target directory? Maven generates a jar or war file to target directory. I'd like to remove that file after maven has installed the jar/war file to local repository (that is, after maven has executed the 'install' goal). The remove could happen either at install goal or separate goal I execute manually.
Note, that I'd like leave other parts of target directory intact, for example target/site and target/surefire-reports.
Just use the clean plugin and run an execution after the install phase:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>${project.build.outputDirectory}</directory>
<includes>
<include>**/*.jar</include>
</includes>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
There is nothing built into Maven that can do this. You could use the antrun plugin to execute an Ant script after install that deletes the artifact, or use the exec plugin to use the command line to delete the artifact, or write your own plug-in.
I suggest there is little value, if any, in doing any of these things. Maven is designed to place intermediate and final artifacts in target to make follow-on builds more efficient. The reason that there is nothing available to do this already is an indicator that this is of little value. If it is of value to you, you have a few options.
I know I am a little bit late. But I guess the issue was, that a maven project archives the artifacts automatically. In my case, I disabled the automatic archiving and just archived the artifacts manually using the post build actions. This way, only the artifacts that I am interested in are archived. I am willing to leave the generated artifacts on disk until the next build runs.

Maven 2 Assembly plugin - how to split main artifacts and dependencies into separate folders

I am using Assembly plugin for maven to create an installation package.
For my packaging requirement, I need to split artifacts generated during the build and all dependencies into separate folders.
My current Assembly manifest is as follows:
<moduleSets>
<moduleSet>
<includes>
<include>test:test</include>
</includes>
<binaries>
<includeDependencies>false</includeDependencies>
<outputDirectory>lib/custom/${artifactId}</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
<moduleSet>
<includes>
<include>test:test</include>
</includes>
<binaries>
<includeDependencies>true</includeDependencies>
<excludes>
<exclude>test:test</exclude>
</excludes>
<outputDirectory>lib/thirdParty/</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
First moduleset correctly generates only currently built assembly.
However, thirdParty includes the currently built assembly as well. How would I go about excluding the files already included in the first set?
Thanks
What about using dependency:copy-dependencies? I use that to copy all deps to target/lib .
One kludgy way to do it is with the maven-antrun-plugin and an ant task. Iterate the contents of lib/custom/${artifactId} and remove any files from lib/thirdParty.
You might want to look at appassembler-maven-plugin. It lets you dump all your runtime dependency jars in a directory. You might be able to hack that up to put your main jar in one folder and then dump the dependencies into another.