【问题标题】:Determine the JVM vendor in Gradle build在 Gradle 构建中确定 JVM 供应商
【发布时间】:2019-12-11 14:00:54
【问题描述】:

我知道JavaVersion.current() 以确定正在使用的JVM 版本。但是有没有办法判断JVM是否来自Oracle、OpenJDK等?

是的,总是可以选择检查系统属性"java.vendor",但由于 Gradle 已经为 Java 版本处理了这个问题,我想知道提供者是否也有便利?

【问题讨论】:

  • 没有。我相信检查java.vendor 是你最好的选择。

标签: gradle build.gradle gradlew


【解决方案1】:

据我所知,Source Code 没有方便的函数来检索 Java 供应商字符串。 Gradle 依赖于系统属性 java.vendor 以及内部代码。

【讨论】:

    【解决方案2】:

    我不得不这样做,而系统属性是最好的方法。这是一个将几个系统属性放入正在组装的 jar 清单中的示例。

    tasks.withType(Jar){
        manifest.attributes.putAll([
    "java-vm-specification-version": System.getProperty("java.vm.specification.version"),
            "java-vm-specification-vendor" : System.getProperty("java.vm.specification.vendor"),
            "java-vm-specification-name"   : System.getProperty("java.vm.specification.name"),
            "java-vm-version"              : System.getProperty("java.vm.version"),
            "java-vm-vendor"               : System.getProperty("java.vm.specification.vendor"),
            "java-vm-name"                 : System.getProperty("java.vm.name"),
            "java-specification-version"   : System.getProperty("java.specification.version"),
            "java-specification-vendor"    : System.getProperty("java.specification.vendor"),
            "java-specification-name"      : System.getProperty("java.specification.name")
        ])
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-21
      • 1970-01-01
      • 2018-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      相关资源
      最近更新 更多