无法使Maven Archetype requiredProperty validationRegex工作



我有一个原型,我正试图添加一个新的requiredProperty,它应该只允许两个可能的值之一:"hibernate"one_answers";hibernate-reactive"。在archetype-metadata.xml中,我定义了如下所示的属性:

<requiredProperty key="quarkus_orm_selection">
<validationRegex><![CDATA[^(hibernate|hibernate-reactive)$]]></validationRegex>
</requiredProperty>

在jshell和其他Java程序中,我已经验证了正则表达式正常工作,但在原型中,当我使用hibernate-ree这样的值进行测试时,原型继续没有错误!

我在JShell中证明了以下正则表达式:

jshell> String[] examples = {"hibernate", "hibernate-reactive", "hibernate-re", "hibernate-ree", "testing", "reactive"}
examples ==> String[6] { "hibernate", "hibernate-reactive", "h ... ", "testing", "reactive" }
jshell> Pattern regex = Pattern.compile("^(hibernate|hibernate-reactive)$")
regex ==> ^(hibernate|hibernate-reactive)$
jshell> Arrays.asList(examples).stream().filter(i -> regex.matcher(i).matches()).forEach(System.out::println)
hibernate
hibernate-reactive

谁能建议我可能做错了什么?我正在使用Maven原型插件版本3.2.0

据我所知,maven原型只有在以交互模式传递属性时才会验证reg-ex的。

我创建了一个原型-post-generate。Groovy脚本(见下文)

src/main/resources/META-INF/archetype-post-generate.groovy:

String ormSelector = request.getProperties().get("quarkus_orm_selection")
def pattern = "^(hibernate|hibernate-reactive)$" // the $ is important!
final match = ormSelector.matches(pattern)
if (!match) {
println "[ERROR] ormSelector: $ormSelector is not valid"
println "[ERROR] please provide an ormSelector that follows this pattern: '$pattern'"
throw new RuntimeException("OrmSelector: $ormSelector is not valid")
}

相关内容

  • 没有找到相关文章

最新更新