I have a Maven project that is an aggregation of a number of sub-projects. This project uses the maven javadoc plugin to aggregate all sub-project javadocs into a single directory in the target/ folder. I have an additional file in the target/ folder that I would like to remain in with the javadoc pages. However, every time I run a clean, this file would be deleted. I was wondering if there was a way to delete the whole target directory and leave only a single file. My plugin is currently configured like so:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<execution>
<executions>
<id>default-clean</id>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>target</directory>
<excludes>
<exclude>path/to/myFile.xml</exclude>
</excludes>
<followSymlinks>false</followSymlinks>
<fileset>
</filesets>
</configuration>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
I saw a similar question here, but the solution doesn't seem to work for me.
I had the same need and after playing a while with the plugin I found a working solution for avoiding to delete specific files inside the target folder.
Let's suppose that you don't want to delete the file do_not_delete in the target folder, this configuration works for me:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>target</directory>
<followSymlinks>false</followSymlinks>
<useDefaultExcludes>false</useDefaultExcludes>
<excludes>
<exclude>do_not_delete</exclude>
</excludes>
</fileset>
</filesets>
</configuration>
</plugin>
Put that static file in a resources folder and let the maven-resources-plugin copy it to the specific target folder.
As you stated, it is possible to explicitly exclude or include files form your project. Are you positive about the exclude path you provided?
<filesets>
<fileset>
<directory>src/main/generated</directory>
<followSymlinks>false</followSymlinks>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>*.java</include>
</includes>
<excludes>
<exclude>MyPathRelativeToDirectoryTag/myFile.xml</exclude>
</excludes>
</fileset>
</filesets>
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?
I´m using maven-assembly-plugin for creating a zip file containing some artifacts and additional stuff. The additional stuff is located at a folder called "Installationattachments". Everything working alright so far. "Installationattachments" also contains a png and an ico file which are also included but these are broken after they´re included.
Here is the plugin declaration of my pom.xml:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/assembly/dep.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<inherited>false</inherited>
</plugin>
And that´s the critical part of the assembly itself:
<!-- installation files -->
<fileSet>
<directory>Installationattachments</directory>
<outputDirectory></outputDirectory>
<lineEnding>unix</lineEnding>
<excludes>
<exclude>*.vbs</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>Installationattachments</directory>
<outputDirectory></outputDirectory>
<lineEnding>dos</lineEnding>
<includes>
<include>*.vbs</include>
</includes>
</fileSet>
The problem is the specification of line endings through the <lineEnding> parameter. The first fileset selects all files that aren't VBS file, so it also selects PNG and ICO files. But since those are binary files, you don't want to set a specific line ending for those.
For lack of a nonFilteredFileExtensions, whose support is asked in MASSEMBLY-849, you can add a third filesets without line ending for images:
<fileSet>
<directory>Installationattachments</directory>
<outputDirectory></outputDirectory>
<lineEnding>unix</lineEnding>
<excludes>
<exclude>*.vbs</exclude>
<exclude>*.ico</exclude>
<exclude>*.png</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>Installationattachments</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.ico</include>
<include>*.png</include>
</includes>
</fileSet>
<fileSet>
<directory>Installationattachments</directory>
<outputDirectory></outputDirectory>
<lineEnding>dos</lineEnding>
<includes>
<include>*.vbs</include>
</includes>
</fileSet>
I have two files in my directory like this:
a.b.so
a.so
I want to delete only a.b.so.
So here is my Maven clean plugin entry in my pom.xml file:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>auto-clean</id>
<phase>prepare-package</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${project.build.directory}/libs/x86</directory>
<includes>
<include>*.so</include>
</includes>
<excludes>
<exclude>a.so</exclude>
<excludes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
Just for some backgorund of this, file a.b.so gets downloaded as a dependency then it gets renamed into a.so just before i execute the above entry. I copy file using maven depedency plugin. I don't know whether this affects the not deletion of a.b.so
In turn it always delete a.so. Even I tried including **/*, but it deletes a.so every time.
It never deletes a.b.so.
For this particular example, you can try to replace this part:
<includes>
<include>*.so</include>
</includes>
<excludes>
<exclude>a.so</exclude>
<excludes>
with
<includes>
<include>a.b.so</include>
</includes>
I have created an additional target directory called "dist" to which I am copying some build artifacts. Because it is not in the default target directories, I add an appropriate to the clean plugin configuration per Delete Additional Files instructions for the plugin, as follows:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<fileset>
<followSymlinks>false</followSymlinks>
<directory>dist</directory>
<includes>
<include>*</include>
</includes>
</fileset>
</configuration>
</plugin>
But the "dist" directory and its contents remains after any "mvn clean". I've tried a number of variants, and checked the output of "mvn help:effective-pom" or the "mvn -X" debug output and, I find:
The configuration is showing up in submodules' effective pom's.
There is no error message
There is no sign of "dist" directories or their contents in the debug output.
Explicit references like <directory>${basedir}/dist</directory> make no difference.
Likewise, using more or less explicit <include> references like ".jar" or "*/*.txt" make no difference.
I'm using maven 3.0.3, clean plugin 2.5. I tried 2.4, just in case. No difference. Also, no permission problems.
I've scanned dozens of examples in Google, and all merely repeat the documentation's instructions. I am relatively new to Maven and still learning. Am I blind to something obvious? Thanks.
You need to include the <fileset> tag within the <filesets> tag
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>dist</directory>
</fileset>
</filesets>
</configuration>
</plugin>
Almost,
Here's a working one:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<followSymlinks>false</followSymlinks>
<directory>${basedir}</directory>
<includes>
<include>dist/**</include>
<include>target</include>
</includes>
</fileset>
</filesets>
</configuration>
Try to use instead of:
<includes>
<include>*</include>
</includes>
Something like
<includes>
<include>**/*.*</include>
</includes>
It worked for me using Maven 2.2.1
This will work:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<fileset>
<followSymlinks>false</followSymlinks>
<directory>${basedir}</directory> <!-- Careful with this -->
<includes>
<include>dist</include>
<include>target</include>
</includes>
</fileset>
</configuration>
</plugin>
With the maven-clean-plugin I would like to remove all folders that start with "tmp". Is this possbile with maven wildcards? I have tried:
<fileset>
<directory>${project.basedir}</directory>
<includes>
<include>**/tmp*</include>
</includes>
</fileset>
Which does not work.
This configuration works for me:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}</directory>
<includes>
<include>**/tmp*/</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
If I add these folders in the project root:
some/tmp/
some/tmpFolder/
some/realFolder/
Then the mvn clean will delete the first two folders and leave the last one.