如何强制特定的JDK供应商作为构建的先决条件? [英] how to enforce a specific JDK vendor as a pre-requisite of the build?

查看:89
本文介绍了如何强制特定的JDK供应商作为构建的先决条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些第三方代码,这些代码依赖于com.sun.javadoc.*包中的类.这种依赖性以及其他一些依赖性意味着代码将仅使用 Sun/Oracle JDK 构建,而不使用 OpenJDK 构建.

I am working with some third party code that has dependencies on classes in the com.sun.javadoc.* package. This and some other dependencies mean that the code will only build with Sun/Oracle JDK, and not OpenJDK.

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

I don't have an option to remove the dependencies, so I would like the build to fail early and with an easy to understand error message if someone tries to build using a JDK that is not supported.

是否可以通过pom文件将JDK供应商和JDK版本强制为Oracle 1.6 JDK?

Is there a way of enforcing the JDK Vendor and JDK Version to be Oracle 1.6 JDK in the pom file?

感谢 carlspring的答案,我设法成功了.尚未在所有供应商和VM版本上进行全面测试,但这只是一个开始.

Thanks to carlspring's answer, I have managed to get this working. It's not thoroughly tested across all vendors and VM versions, but it's a start.

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

推荐答案

我建议您使用

I would suggest you use the maven-enforcer-plugin and write your own custom rule.

这篇关于如何强制特定的JDK供应商作为构建的先决条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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