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?
Of course, the Apache Maven Enforcer Plugin is your friend, especially the RequireProperty Rule