Reputation: 283
I've got a WAR file, which is included as a dependency in my assembly module. The WAR file contains some properties, which I'd like to exclude in my newly generated WAR file.
Due to unknown reasons the exclusion doesn't work. Even if I exclude all the property files using **/*.properties
, the files are not excluded. Any idea what's wrong here?
Maven Pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.mycompanyname.myprojectname</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>demo-dashboard-assembly</artifactId>
<packaging>pom</packaging>
<name>demo-dashboard-assembly</name>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<goals></goals>
<executions>
<execution>
<id>delivery-prod</id>
<phase>prepare-package</phase>
<goals><goal>single</goal></goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>demo#prod#dashboard</finalName>
<descriptors>
<descriptor>src/main/assembly/delivery.prod.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>de.mycompanyname</groupId>
<artifactId>myprojectname.dashboard</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
delivery.prod.xml
<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>delivery</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<excludes>
<exclude>WEB-INF/classes/commonDashboard.dev.properties</exclude>
<exclude>WEB-INF/classes/commonDashboard.test.properties</exclude>
<exclude>WEB-INF/classes/db.dev.properties</exclude>
<exclude>WEB-INF/classes/db.test.properties</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assebly>
Upvotes: 1
Views: 706
Reputation: 137064
The problem is that you're not using the right <exclude>
configuration.
By specifying an <exclude>
at the <dependencySet>
level,
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<excludes>
<exclude>WEB-INF/classes/commonDashboard.dev.properties</exclude>
<!-- more excludes -->
</excludes>
</dependencySet>
you're specifying the dependencies that should be excluded in this set. That is to say, it is specifying the dependencies that should not be unpacked to the root folder here. Clearly, since there are no WEB-INF/classes/...
dependencies, it doesn't match and do anything. In fact, it will raise a warning, that you can see in the logs:
[WARNING] The following patterns were never triggered in this artifact exclusion filter:
o 'WEB-INF/classes/commonDashboard.dev.properties'
o 'WEB-INF/classes/commonDashboard.test.properties'
o 'WEB-INF/classes/db.dev.properties'
o 'WEB-INF/classes/db.test.properties'
What you want instead, is to exclude files within the dependencies that are unpacked. For that, you need to use the <unpackOptions>
element, which contains an exclude configuration:
Specifies options for including/excluding/filtering items extracted from an archive. (Since 2.2-beta-1)
As such, you should have instead:
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<exclude>WEB-INF/classes/commonDashboard.dev.properties</exclude>
<exclude>WEB-INF/classes/commonDashboard.test.properties</exclude>
<exclude>WEB-INF/classes/db.dev.properties</exclude>
<exclude>WEB-INF/classes/db.test.properties</exclude>
</excludes>
</unpackOptions>
</dependencySet>
</dependencySets>
This will correctly exclude the selected files during the unpacking of each dependency, and the resulting assembly will not have them. Note that you could use a regular expression instead of specifying each file; for example:
<exclude>%regex[WEB-INF\/classes\/(commonDashboard|db)\.(dev|test)\.properties]</exclude>
Upvotes: 1