I am using Maven Assembly Plugin. I am getting a parameter called env
from mvn
command to assembly description. Based on it, assembly decides which configurations to use for distribution. Is there any way to make this parameter mandatory so that if user doesn't pass this parameter then build will fail?
How about using the Enforcer plugin's required property rule?
You could add:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-property</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>env</property>
<message>You must set an env property!</message>
<regex>^(?!\s*$).+</regex>
<regexMessage>Env property validation failed</regexMessage>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
Which would require that -Denv
is set, and equal to at least one non space character:
mvn clean verify
...
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
You must set an env property!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.557 s
[INFO] Finished at: 2017-11-27T19:30:06-05:00
[INFO] Final Memory: 10M/309M
[INFO] ------------------------------------------------------------------------
mvn clean verify -Denv=test
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.965 s
[INFO] Finished at: 2017-11-27T19:30:59-05:00
[INFO] Final Memory: 27M/309M
[INFO] ------------------------------------------------------------------------