【问题标题】:How to find the minimum JDK version of a specific version of maven dependency?如何找到特定版本的maven依赖项的最低JDK版本?
【发布时间】:2017-03-21 17:44:07
【问题描述】:

现在我使用JDK1.5开发程序,所以我必须保证我要使用的maven依赖与JDK 1.5兼容。有时,最新版本需要高于 1.5 的 jdk,但旧版本可能适合。 但是如何找到特定版本的maven依赖的最低JDK版本呢? 我试过 mvnrepository.com 但找不到 jdk 要求。一些项目主页只显示最新版本的 jdk 需求。 任何人都可以帮助我吗?谢谢!

【问题讨论】:

  • 我们是在讨论手动检查还是以编程方式检查最低 JDK 版本?
  • 最好的解决方案是检查您通过animal-sniffer-maven-plugin 使用的依赖项,如果您使用其他依赖项,您的构建将失败。除此之外,我建议升级到 Java 7 或 8...

标签: java maven maven-dependency


【解决方案1】:

您可以检查类文件的主要/次要版本。如果 JAR 是使用 Maven 构建的,您可以在 META-INF/MANIFEST.MF 文件中检查用于构建它的 JDK 版本,这很可能是最低版本。

在不下载 JAR 的情况下进行检查的一种方法是检查 maven Central 上的 POM,例如

http://search.maven.org/#artifactdetails%7Cnet.openhft%7Cchronicle-queue%7C4.5.15%7Cbundle

需要 1.8

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerArgument>-Xlint:deprecation</compilerArgument>
                <compilerArgument>-XDignore.symbol.file</compilerArgument>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>

需要考虑的一点是,如果 Oracle 及其所有资源不免费支持 Java 7,您会吗?

【讨论】:

    【解决方案2】:

    大多数时候你可以这样做

     <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>{java.sourceversion}</source>
                    <target>{java.targetversion}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    这应该足够了。

    【讨论】:

      猜你喜欢
      • 2011-02-03
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      • 2011-06-20
      • 2016-09-18
      • 2014-10-13
      • 2016-12-05
      • 1970-01-01
      相关资源
      最近更新 更多