3

我正在使用一些第三方代码,这些代码依赖于com.sun.javadoc.*包中的类。这个和其他一些依赖意味着代码只能使用Sun/Oracle JDK构建,而不是OpenJDK

我没有删除依赖项的选项,因此如果有人尝试使用不受支持的 JDK 进行构建,我希望构建能够尽早失败并提供易于理解的错误消息。

有没有办法在 pom 文件中强制 JDK 供应商和 JDK 版本为 Oracle 1.6 JDK?


编辑:

感谢carlspring 的回答,我已经成功地完成了这项工作。它没有在所有供应商和 VM 版本中进行彻底测试,但它是一个开始。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.3.1</version>
    <executions>
      <execution>
        <id>enforce-property</id>
        <goals>
          <goal>enforce</goal>
        </goals>
        <configuration>
          <rules>
            <requireProperty>
              <property>java.vendor</property>
              <message>Java Vendor must be Sun/Oracle.</message>
              <regex>Sun Microsystems Inc\.</regex>
              <regexMessage>Java Vendor must be Sun/Oracle.</regexMessage>
            </requireProperty>
            <requireProperty>
              <property>java.runtime.name</property>
              <message>Java Vendor must be Sun/Oracle.</message>
              <regex>Java\(TM\) SE Runtime Environment</regex>
              <regexMessage>Java Vendor must be Sun/Oracle.</regexMessage>
            </requireProperty>
          </rules>
          <fail>true</fail>
        </configuration>
      </execution>
    </executions>
  </plugin>
4

1 回答 1

3

我建议您使用maven-enforcer-plugin并编写自己的自定义规则。

于 2013-08-04T17:49:55.990 回答