I\'m setting up a maven build, and the destination server needs to be specified on the command line as a property (which is then used to select the appropriate profile), eg<
To elaborate on edbrannin's alternate solution:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourcompany</groupId>
<artifactId>yourproject</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>checkParam</id>
<phase>initialize</phase>
<goals><goal>run</goal></goals>
<configuration>
<tasks>
<fail message="'env' property must be set" unless="env"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
will give you the following output:
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An Ant BuildException has occured: 'env' property must be set
IMHO the most straightforward way to do it (the one I'd go for personally).
You could even control a set of allowed values using a nested <condition>
containing <or>
and <equals>
tags (see the Ant manual: http://ant.apache.org/manual/Tasks/conditions.html)
My first inclination would be to make a Profile that's active whenever the env property is unset, and have it fail somehow. Perhaps you could write a Maven Plugin that tests for that property and fails if it's not present?
Alternately, you could probably test for it with a very small ant-build script.
Maybe you could use such a workaround: in Maven you can activate a profile if some property is not set:
<project>
...
<profiles>
<profile>
<id>failure_profile</id>
<activation>
<property>
<name>!env</name>
</property>
</activation>
</profile>
</profiles>
</project>
Then you shall force this profile always fail, e.g. using maven-enforcer-plugin:
<profile>
<id>failure_profile</id>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<AlwaysFail/>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
If you don't provide -Denv build will then fail:
[INFO] [enforcer:enforce {execution: enforce}]
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.AlwaysFail failed with message:
Always fails!
[INFO] ---------------------------------------------------------
[ERROR] BUILD ERROR
Well, it's much more verbose then Ant, but pure Maven :)
Everyone is close, but there's a rule in the enforcer to specifically check for a property, no ant or funky profiles required: http://maven.apache.org/enforcer/enforcer-rules/requireProperty.html
The rule can also check the value of the property.