15

Now I use the JDK1.5 to develop the program, so I have to guarantee the maven dependencies I want to use are compatible with the JDK 1.5 . Sometimes, latest version needs jdk higher than 1.5 but older version may fit. But how to find the minimum JDK version of a specific version of maven dependency? I have tried mvnrepository.com but can not find the jdk requirement. Some project home page only show the jdk requirement of latest version. Anyone can help me? Thank you!

Germinate
  • 2,008
  • 2
  • 14
  • 23
  • 1
    are we talking about manually checking or programmatically checking for minimum JDK version? – blurfus Nov 08 '16 at 07:25
  • The best solution is to check the dependencies you use via [animal-sniffer-maven-plugin](http://www.mojohaus.org/animal-sniffer/animal-sniffer-maven-plugin/) and will fail your build if you use different. Apart from that I would suggest to upgrade to Java 7 or 8... – khmarbaise Nov 08 '16 at 09:22

3 Answers3

5

You can check the major/minor version of the class files. If the JAR was built with Maven you can check the version of the JDK used to build it in the META-INF/MANIFEST.MF file which is most likely the minimum version.

A way to check without downloading the JAR is to check the POM on maven central e.g.

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

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

Something to consider, if Oracle with all it's resources doesn't support Java 7 for free, should you?

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • I think that 'META-INF/MANIFEST.MF' is not contracted to have such an information. Even worse, not all POMs have node with and nodes. For example for 'org.testng:testng:7.6.1' neither of your ways of checking will work. – zer_ik Aug 12 '22 at 05:58
  • @zer_ik If the information isn't anywhere else, you will have to try the jar or read it. – Peter Lawrey Aug 13 '22 at 07:01
0

Most of the times you can do like this

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

this should be enough.

Avinash
  • 2,093
  • 4
  • 28
  • 41
0

It seems that the only one hundred percent solution is to check minimum required JDK version for .class files inside jar. Check this question.

zer_ik
  • 410
  • 1
  • 4
  • 14