Get libraries for particular java version

Viewed 39

I have following lines in my Maven Eclipse project that brings me log4j libraries.

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.11.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.11.1</version>
    </dependency>
</dependencies>

How to be sure I'm getting log4j libraries build for java 1.8 ?

1 Answers

I suppose you mean that those libraries don't need JDK9 or higher.. you won't building them you only use them as dependencies on the classpath. So they can being built with JDK7 or even lower (there are some rare quirks yes) but the general rule is that will work. What not will work if a library needs a high version for example JDK11 or alike.

This can be checked by using the maven-enforcer-plugin with the extra-enforcer-rules like this:

<project>
 <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>enforce-bytecode-version</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <enforceBytecodeVersion>
                  <maxJdkVersion>8</maxJdkVersion>
                </enforceBytecodeVersion>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>extra-enforcer-rules</artifactId>
            <version>1.3</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

This will check the byte code of the dependencies and will fail if a dependency needs a higher JDK version than given (<maxJdkVersion>8</maxJdkVersion>).

Related