Search code examples
javagradlelibraries

Java compatibility of Java library


How do I determine which Java version a Java library is compatible with?

For reference, I need to upgrade the following libraries:

// build.gradle

dependencies {
  compile('javax.mail:mail:1.4')
  compile group: 'org.apache.velocity', name: 'velocity', version: '1.7'
}

And my Spring Boot project uses Java 8.

I would like to know if newer versions of these 2 libraries will still support Java 8.

Right now, I'm looking at the mvnrepository page for JavaMail API here, but I don't see anything being mentioned about which Java version is being supported.


Solution

  • If you're using Spring Boot 2.7, then you should replace that javax.mail:mail:1.4 dependency with:

    <dependency>
      <groupId>com.sun.mail</groupId>
      <artifactId>jakarta.mail</artifactId>
    </dependency>
    

    or for Gradle:

    compile('com.sun.mail:jakarta.mail')
    

    (no version, Spring Boot manages it for you, which for Spring Boot 2.7.19 will resolve to com.sun.mail:jakarta.mail:1.6.7.)

    JakartaMail/JavaMail 1.6.x supports Java 7 and higher.

    If you upgrade to Spring Boot 3.x (which requires Java 17), you'll need to use

    <dependency>
      <groupId>org.eclipse.angus</groupId>
      <artifactId>angus-mail</artifactId>
    </dependency>
    

    or for Gradle:

    compile('org.eclipse.angus:angus-mail')
    

    Going to Spring Boot 3.x would also involve changes in the namespace of the API (from javax.mail to jakarta.mail), so that will require some code changes.

    For Velocity, you probably need to upgrade to version 2.3 (which supports Java 8 or higher), see the Apache Velocity site, but I'm not sure what is involved in upgrading from version 1.7 to 2.3, so that might be a lot of work (e.g. see the 2.0 documentation Upgrading from earlier versions; also check the 2.3 documentation for 2.1, 2.2 and 2.3 changes).