Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
maven中是否有方法确保设置了属性_Maven_Maven 3_Pom.xml - Fatal编程技术网

maven中是否有方法确保设置了属性

maven中是否有方法确保设置了属性,maven,maven-3,pom.xml,Maven,Maven 3,Pom.xml,我刚刚发现了一个很难解决的maven问题,它是由错误的属性值引起的 属性是测试在运行时使用的备用JVM的路径。 我希望通过检测路径是否有效,使maven尽早失败。 实现这一目标的方法是什么 我计划深入安特伦,看看是否有办法让它先运行,这样它就可以检查了,但这似乎有些过头了 问题:如何简洁明了地执行此操作?您可以使用及其规则,其中您可以强制存在某个属性,可以选择使用某个值(匹配的正则表达式),否则将导致生成失败 此规则可以强制设置已声明的属性,并可以根据正则表达式对其求值 一个简单的片段是:

我刚刚发现了一个很难解决的maven问题,它是由错误的属性值引起的

属性是测试在运行时使用的备用JVM的路径。 我希望通过检测路径是否有效,使maven尽早失败。 实现这一目标的方法是什么

我计划深入安特伦,看看是否有办法让它先运行,这样它就可以检查了,但这似乎有些过头了

问题:如何简洁明了地执行此操作?

您可以使用及其规则,其中您可以强制存在某个属性,可以选择使用某个值(匹配的正则表达式),否则将导致生成失败

此规则可以强制设置已声明的属性,并可以根据正则表达式对其求值

一个简单的片段是:


org.apache.maven.plugins
maven enforcer插件
1.4.1
强制执行财产
执行
巴塞迪尔
您必须设置basedir属性!
.*\d*
basedir属性必须至少包含一个数字。
真的
是的,您可以使用来执行此任务。此插件用于在生成过程中强制执行规则,它有一个内置规则:

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

以下配置将强制文件
${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>

org.apache.maven.plugins
maven enforcer插件
1.4.1
强制文件存在
执行
${project.build.outputDirectory}/foo.txt
真的
使用Maven Enforcer插件的规则

  <build>
    <plugins>
      <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>${property.to.check}</file>
                  </files>
                </requireFilesExist>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

org.apache.maven.plugins
maven enforcer插件
1.4.1
强制文件存在
执行
${property.to.check}
真的

啊,有趣的是,我们建议使用相同的插件,而不是相同的规则:D.@Tunaki ahahaha nice,好的,然后由OP检查哪一个最适合他/她的需要。很好,这可以与正则表达式进行比较,但另一个稍微简单一点,如果我们有一个代码工作,可能会让实习生不那么困惑。谢谢。请澄清:是否要检查属性是否已设置或文件是否存在?标题和你的问题似乎要求不同的东西(因此有两个不同的答案:D)
  <build>
    <plugins>
      <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>${property.to.check}</file>
                  </files>
                </requireFilesExist>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>