Check if library will work on a specific verion of Java

后端 未结 2 646
说谎
说谎 2021-01-13 22:15

What approach can be taken to verify that a library is compatible on a specific version of Java?

Example: Library X was compiled on Java 1.7, therefor it might not w

相关标签:
2条回答
  • 2021-01-13 22:24

    The best is to check the byte code via an enforcer rule which can be applied to your build by using the maven-enforcer-plugin...

    <project>
      [...]
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <version>1.4.1</version>
            <executions>
              <execution>
                <id>enforce-bytecode-version</id>
                <goals>
                  <goal>enforce</goal>
                </goals>
                <configuration>
                  <rules>
                    <enforceBytecodeVersion>
                      <maxJdkVersion>1.7</maxJdkVersion>
                    </enforceBytecodeVersion>
                  </rules>
                  <fail>true</fail>
                </configuration>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>extra-enforcer-rules</artifactId>
                <version>1.0-beta-4</version>
              </dependency>
            </dependencies>
          </plugin>
        </plugins>
      </build>
      [...]
    </project>
    
    0 讨论(0)
  • 2021-01-13 22:40

    compile with the version you want:

    javac -target ...
    

    see that: How do i compile a .java with support for older versions of java?

    and check jar dependencies: with Jdepend for example

    Analyze JAR dependencies in a Java project

    0 讨论(0)
提交回复
热议问题