Reputation: 2542
If I add the following property in my POM, the maven-war-plugin
uses it correctly:
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
However if I add the following property the plugin ignores it (the generated WAR has the default name, i.e. artifactId-version):
<properties>
<war.warName>${project.artifactId}</war.warName>
</properties>
Here are two excerpts from the maven-war-plugin
documentation:
warName:
failOnMissingWebXml:
(Source: https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html)
Why is the behavior different between failOnMissingWebXml
and war.warName
?
Also, if other plugins can use the value ${project.build.sourceEncoding}
why can't maven-war-plugin
use the value of ${project.build.finalName}?
<properties>
<!-- plugins use these values correctly -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- not "found" by maven-war-plugin -->
<war.warName>${project.artifactId}</war.warName>
<project.build.finalName>${project.artifactId}</project.build.finalName>
</properties>
Thanks a lot! :)
EDIT: Since the version 2.4 of maven-war-plugin
war.warName works as expected, however I still don't understand why setting project.build.finalName
doesn't work.
Upvotes: 3
Views: 5590
Reputation: 97399
The problem is simply that you mistaken property cause user property
is meant to be used usually from command like this:
mvn -Dwar.warName=xxx war:war
If you like to use it in a pom file you have to use it like this:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warName>WhatEverYouLike</warName>
</configuration>
</plugin>
...
</plugins>
</build>
...
And you shouldn't use properties in your pom to define such things. Better use the configuration tag for this.
The ${project.build.finalName}
should be used like this:
<project..>
<build>
<finalName>WhatYouLIke</finalName>
..
</build>
</project>
The structure can be seen if you look into the maven model.
The usage of ${project.build.sourceEncoding}
is simply a convention in Maven plugins so you could define that property which is picked up by a larger number of plugins to be used for source encoding (I have to admit this is a little bit misleading). The original idea behind was having something in the maven model to represent the encoding which would mean to change it which is not really possible at the moment.
Upvotes: 4