This can still be done using the Maven Enforcer Plugin.
Although the mutual exception, <requireActiveProfile>...<all>false</all>... wrong, as @khmarbaise reported, there is still a built-in <evaluateBeanshell/> rule that allows you to do whatever it wants.
I wrote specifically for this case: XOR of two profiles. Hope this helps.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.4.1</version> <executions> <execution> <id>enforce-PROFILE_ONE-XOR-PROFILE_TWO-is-active</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requireActiveProfile> <profiles>PROFILE_ONE,PROFILE_TWO</profiles> <all>false</all> </requireActiveProfile> <evaluateBeanshell> <condition><![CDATA[ // ensure PROFILE_ONE XOR PROFILE_TWO print("Checking if only one of PROFILE_ONE and PROFILE_TWO profiles is active ..."); boolean profile1 = false, profile2 = false; for(s: "${project.activeProfiles}".replaceAll("\\[?\\s?Profile \\{id: (?<profile>\\w+), source: \\w+\\}\\]?", "${profile}").split(",")) { if("PROFILE_ONE".equalsIgnoreCase(s)){ profile1 = true;} if("PROFILE_TWO".equalsIgnoreCase(s)){ profile2 = true;} } print("PROFILE_ONE XOR PROFILE_TWO: "+(profile1 != profile2)); return profile1 != profile2; ]]></condition> </evaluateBeanshell> </rules> <failFast>true</failFast> </configuration> </execution> </executions> </plugin>
The tricky part is the active profile cycle, which I have already done here. If you need, you can expand it to more than two profiles. But you have to write a long xor expression, since beanshell does not implement the Java xor ^ operator.
aymens
source share