Sol*_*olx 5 pom.xml maven-3 maven
我刚刚追踪了一个由不良财产价值引起的困难的maven问题.
该属性是备用JVM的路径,该JVM通过测试用于运行时.我想通过检测路径是否有效来使maven早期失败.什么可能是一种方法来实现这一目标?
我打算深入了解antrun,看看是否有办法让它先运行以便它可以检查,但这似乎有点矫枉过正.
问题:如何干净简单地完成这项工作?
您可以使用Enforcer Maven 插件及其Require Property规则,您可以在其中强制某个属性的存在,可选择使用某个值(匹配的正则表达式),否则构建失败。
此规则可以强制设置已声明的属性,并可选择根据正则表达式对其进行评估。
一个简单的片段是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</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>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
是的,您可以使用maven-enforcer-plugin来完成此任务。该插件用于在构建过程中强制执行规则,它有一个内置requireFilesExist规则:
此规则检查指定的文件列表是否存在。
以下配置将强制该文件${project.build.outputDirectory}/foo.txt存在,如果不存在,则构建失败。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-files-exist</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireFilesExist>
<files>
<file>${project.build.outputDirectory}/foo.txt</file>
</files>
</requireFilesExist>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
969 次 |
| 最近记录: |