I am starting to work on a poorly documented Maven project. I have set up my profile for the project but I may or may not be missing property definitions that used during resource filtering. By default, if a property is not defined in a filtered file, the variable name is left in the copied resource and Maven continues silently.
Is there a way to force Maven to fast-fail in this case?
As a minimal example, take this pom,
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>production</id>
<properties>
<foo>Craig</foo>
</properties>
</profile>
</profiles>
</project>
And have a resource to filter:
echo 'Hello, my name is ${foo}!' > src/main/resources/test
Then running mvn clean install -Pproduction
produces a file that says Hello, my name is Craig!
while running mvn clean install
produces a file that says Hello, my name is ${foo}!
.
So my question is; how do I force Maven to fail in the second case?
You can use Maven to perform variable replacement on project resources. When resource filtering is activated, Maven will scan resources for property references surrounded by ${ and }.
Apache Maven Resources Plugin – Including and excluding files and directories.
The Resources Plugin handles the copying of project resources to the output directory. There are two different kinds of resources: main resources and test resources.
Source Directories The Maven property ${project. basedir} defaults to the top level directory of the project, so the build directory defaults to the target directory in project base dir. It also sets the property ${project.
JIRA issues exist for this feature in The Codehause database:
You can log in and vote for them. Unfortunately the demand for this important safety net feature seems to be low ... strange.
Of course, the Apache Maven Enforcer Plugin is your friend, especially the RequireProperty Rule
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With