此规则可以强制设置已声明的属性,并可选择根据正则表达式对其进行评估。
此规则支持以下参数:
正则表达式应用于属性的整个值(即使用正则表达式“匹配”方法),而不仅仅是属性值的子字符串。
示例插件配置:
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>enforce-property</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requireProperty> <property>basedir</property> <message>You must set a basedir property!</message> <regex>.*\d.*</regex> <regexMessage>The basedir property must contain at least one digit.</regexMessage> </requireProperty> <requireProperty> <property>project.version</property> <message>"Project version must be specified."</message> <regex>.*(\d|-SNAPSHOT)$</regex> <regexMessage>"Project version must end in a number or -SNAPSHOT."</regexMessage> </requireProperty> </rules> <fail>true</fail> </configuration> </execution> </executions> </plugin> </plugins> </build> [...] </project>