Maven 中是否有一种方法可以确保设置了属性 [英] Is there a way in maven to assure that a property is set

查看:64
本文介绍了Maven 中是否有一种方法可以确保设置了属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚找到了一个由不良属性值引起的困难的 Maven 问题.

I just tracked down a difficult maven issue that was caused by a bad property value.

该属性是测试运行时使用的备用 JVM 的路径.我想通过检测路径是否有效来使 maven 尽早失败.什么可能是实现这一目标的方法?

The property is a path to an alternate JVM that is used a run-time by a test. I would like to make maven fail early by detecting if the path is valid or not. What might be a way to accomplish this?

我打算深入研究 antrun,看看是否有办法让它先运行,以便它可以检查,但这似乎有点过头了.

I plan to dig into antrun to see if there is a way to make it run first so that it can check, but that seems like overkill.

问题:我怎样才能干净、简单地做到这一点?

Question: How can I do this cleanly and simply?

推荐答案

是的,您可以使用 maven-enforcer-plugin 用于此任务.这个插件用于在构建过程中强制执行规则,它有一个内置的 requireFilesExist 规则:

Yes, you can use the maven-enforcer-plugin for this task. This plugin is used to enforce rules during the build and it has a built-in requireFilesExist rule:

此规则检查指定的文件列表是否存在.

This rule checks that the specified list of files exist.

以下配置将强制文件 ${project.build.outputDirectory}/foo.txt 存在,如果不存在,则构建失败.

The following configuration will enforce that the file ${project.build.outputDirectory}/foo.txt exists and will fail the build if it does not.

<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>

这篇关于Maven 中是否有一种方法可以确保设置了属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆