Maven clean not deleting files - maven

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>

Related

Cant generate hash for files from two different folder using checksum-maven-plugin

I'm trying to generate the hash using checksum-maven-plugin from the POM file. I need to generate the hash for each file from two different folders and generate two .sha files. I tried with the below plugin in POM but it only generates the hash for the second one i.e. for *.sql.
<plugins>
<plugin>
<groupId>net.nicoulaj.maven.plugins</groupId>
<artifactId>checksum-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<goals>
<goal>files</goal>
</goals>
</execution>
</executions>
<configuration>
<algorithms>
<algorithm>SHA-1</algorithm>
</algorithms>
<fileSets>
<fileSet>
<directory>${basedir}/locale</directory>
<includes>
<include>*.tsv</include>
</includes>
</fileSet>
</fileSets>
<individualFiles>false</individualFiles>
<attachChecksums>true</attachChecksums>
<csvSummary>false</csvSummary>
<shasumSummary>true</shasumSummary>
<shasumSummaryFile>${artifactId}-${version}_locale.sha</shasumSummaryFile>
</configuration>
</plugin>
<plugin>
<groupId>net.nicoulaj.maven.plugins</groupId>
<artifactId>checksum-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<goals>
<goal>files</goal>
</goals>
</execution>
</executions>
<configuration>
<algorithms>
<algorithm>SHA-1</algorithm>
</algorithms>
<fileSets>
<fileSet>
<directory>${basedir}/sql</directory>
<includes>
<include>*.sql</include>
</includes>
</fileSet>
</fileSets>
<individualFiles>false</individualFiles>
<attachChecksums>true</attachChecksums>
<csvSummary>false</csvSummary>
<shasumSummary>true</shasumSummary>
<shasumSummaryFile>${artifactId}-${version}_sql.sha</shasumSummaryFile>
</configuration>
</plugin>
Appreciate any suggestion.

maven-assembly-plugin png and ico broken

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>

Move a text file into target folder when compiling a Maven project

I have a slight different version of the question that I made recently.
I have a Maven project under Netbeans 7.3, which doesn't have any build.xml file to configure building options, while there is the pom.xml that I use to import other libraries. Now, I have a text file (let's say textfile.txt) stored in the project folder in Netbeans 7.3, e.g.
project folder
textfile.txt
src
package
package.subpackage
MyClass.java
When I compile I get a target folder where the jar file is put in, e.g.
project folder
textfile.txt
target
classes
generated-sources
....etc
test-classes
MyProject.jar
src
package
package.subpackage
MyClass.java
How can I make the file textfile.txt being copied under target folder when I compile the Maven project?
A first way is to put the files into src/main/resources that is the folder devoted to store the complied resources, i.e. the resources included into the jar file (e.g. images for the icons).
If you need to make the config file to be distributed with the jar, but separated by it, you must edit the pom.xml file. A possible answer is the to add the following plugin between the <plugins> and </plugins> tags.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Using env.test.properties</echo>
<copy file="textfile.txt" tofile="${basedir}/target/textfile.txt"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Moreover, as you can read here you can also import all the resources from an "input" directory to an "output" directory inside target by using the dedicated plugin, e.g.:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/output</outputDirectory>
<resources>
<resource>
<directory>input</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
The simplest way, to use some resource as I know (additional information about resources configuration you can find here: https://maven.apache.org/plugins/maven-resources-plugin/):
<build>
<plugins>
<!-- your plugins, including or not maven-resource-plugin -->
</plugins>
<resources>
<resource>
<filtering>true</filtering><!-- if it is neccessary -->
<directory>${project.basedir}</directory><!-- from -->
<targetPath>${project.build.directory}</targetPath><!-- to -->
<includes><!-- what -->
<include>textfile.txt</include>
</includes>
</resource>
</resources>
</build>
For building my setting files and updating production this worked for me:
<build>
<resources>
<resource>
<directory>${project.basedir}</directory><!-- from -->
<targetPath>${project.build.directory}</targetPath><!-- to -->
<includes><!-- what -->
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
To have an absolute control of the output of your build you can use the "Apache Maven Assembly Plugin". You can define pretty much everything (format, subfolders...).
The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.
More info
You have to install the plugin in your pom file:
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/yourassembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>x.x</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/yourassembly.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>
</pluginManagement>
In your case the descriptor "yourassembly.xml" would be as follows:
<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>yourassembly</id>
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>textfile.txt</include>
</includes>
</fileSet>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
</fileSets>
</assembly>

Maven clean ignore single file

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>

Maven clean plugin exclude .cvsignore

In my project I originally made a mistake and committed the target directory in the cvs repository; I know there is no safe way to remove a directory from CVS, so I put a .cvsignore file there to basically ignore everything (I don't want developers who aren't able to even merge properly to commit their classes...).
The problem raises with my Jenkins CI, because I run clean and test goals; basically clean is run before CVS update, so it always finds a file to update (the .cvsignore that has been wiped by clean) and triggers an often useless build.
I think the way to go is to use exclusions but I tried and did not work:
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting file set: **************************/target (included: [**], excluded: [])
The exclusion is configured as:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>not-clean</id>
<configuration>
<filesets>
<fileset>
<directory>target</directory>
<excludes>
<exclude>*cvsignore</exclude>
</excludes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
You could try setting <excludeDefaultDirectories> to true, Otherwise, I believe target folder would always get deleted.
The following code snippet works for me. Note that I have used default-clean as the id.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>default-clean</id>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>target</directory>
<excludes>
<exclude>.cvsignore</exclude>
<exclude>CVS</exclude>
<exclude>CVS/**</exclude>
</excludes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>

Resources