这个:
…是定义必需属性(带有默认值和验证)的方法.但是,IIRC是在原型插件的v3.0.0中引入的,因此也许您使用的是以前的版本.
编辑1:针对此问题“ validationRegex是否可以应用于artifactId和groupId”.是的,它可以.可以将其应用于requiredProperties中的任何条目,但需要注意以下几点:validationRegex仅适用于命令行提供的输入,因此提供defaultValue或通过命令行参数(-DgroupId = …,-DartifactId =定义值). ..)边步骤验证.这是一个具体示例,在archetype-descriptor.xml中提供了以下requiredProperties:
^[a-z]*$
COM.XYZ.PQR
^[a-z]*$
以下命令:mvn archetype:generate -DarchetypeGroupId = … -DarchetypeArtifactId = … -DarchetypeVersion = … -DgroupId = com.foo.bar将导致com.foo.bar用于groupId,而用户将提示您提供一个artifactId,如下所示:
Define value for property ‘username’ (should match expression ‘^[a-z]*$’): Whatever
Value does not match the expression, please try again: whatever
Define value for property…
到目前为止,一切都很好.
但是以下命令mvn archetype:generate -DarchetypeGroupId = … -DarchetypeArtifactId = … -DarchetypeVersion = … -DartifactId =无论如何,都会导致COM.XYZ.PQR用于groupId,即使这不符合validationRegex.
同样下面的命令mvn archetype:generate -DarchetypeGroupId = … -DarchetypeArtifactId = … -DarchetypeVersion = … -DartifactId = WHATEVER会导致COM.XYZ.PQR被用于groupId,而无论被用于artifactId,值不符合validationRegex.
因此,总而言之:validationRegex适用于任何requiredProperty(无论是保留属性(例如artifactId)还是定制属性),但仅适用于以交互方式提供的值,因此设置默认值或通过命令提供值行参数侧步骤验证.
注意:即使您确实使用validationRegex,您也可能要考虑使用Maven Enforcer插件的requireProperty rule,因为在使用原型创建项目后,可以更改要执行的项目属性.从文档:
This rule can enforce that a declared property is set and optionally evaluate it against a regular expression.
这是一个例子:
org.apache.maven.plugins
maven-enforcer-plugin
3.0.0
enforce-property
enforce
project.artifactId
"Project artifactId must match ...some naming convention..."
...naming convention regex...
"Project artifactId must ..."
true