Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Multi-Release JAR Files #235

Open
Sineaggi opened this issue Jun 4, 2024 · 9 comments
Open

Support Multi-Release JAR Files #235

Sineaggi opened this issue Jun 4, 2024 · 9 comments
Labels
enhancement New feature or request jvm

Comments

@Sineaggi
Copy link

Sineaggi commented Jun 4, 2024

Multi-release jars https://openjdk.org/jeps/238 should have identical api surfaces, but if we create an mr-jar with a new or altered function signature, that's not currently checked by the plugin.

@fzhinkin fzhinkin added enhancement New feature or request jvm labels Jun 4, 2024
@fzhinkin
Copy link
Collaborator

fzhinkin commented Jun 5, 2024

Jar tool validates that public API does not diverge between classes for different release versions and prints something like:

entry: META-INF/versions/11/Specific.class, contains a new public class not found in base entries
entry: META-INF/versions/11/Common.class, contains a class with different api from earlier version
invalid multi-release jar file mrj.jar deleted

@Sineaggi, do you experience issues with invalid multi-release jars? Could you please elaborate on how these jars were created (manually, via gradle/maven/etc. plugin)?

@Sineaggi
Copy link
Author

Sineaggi commented Jun 5, 2024

I'm using gradle to create the jars.

tasks.jar {
    from(compileJava9Java.flatMap { it.destinationDirectory }) {
        into("META-INF/versions/9")
    }
    manifest {
        attributes["Multi-Release"] = "true"
    }
}

I'm guessing Gradle doesn't use the jar tool to create jars.

@Sineaggi
Copy link
Author

Sineaggi commented Jun 5, 2024

Ok so building a new tar task that calls the java jar tool does properly warn.

entry: META-INF/versions/9/org/example/Common.class, contains a class with different api from earlier version
invalid multi-release jar file /Users/cwalker/git/mrjar-compat-check/build/libs/mrjar-compat-check-jar.jar deleted

FAILURE: Build failed with an exception.

Maybe this is better suited to an issue upstream in Gradle.

@Sineaggi
Copy link
Author

Sineaggi commented Jun 5, 2024

Was able to get a gradle task to validate the jar produced by gradle

tasks.register<JavaExec>("validateJar") {
    mainModule = "jdk.jartool/sun.tools.jar.Main"
    val jarFile = tasks.jar.flatMap { it.archiveFile }
    inputs.file(jarFile)
    argumentProviders.plusAssign(CommandLineArgumentProvider {
        listOf(
            "--validate",
            "--file",
            jarFile.get().toString(),
        )
    })
}

@JakeWharton
Copy link

The jar tool is relatively slow and doesn't have enough options which is why almost every build tool uses something else. A jar is, after all, just a zip. They optimize for performance.

@Sineaggi
Copy link
Author

Sineaggi commented Jun 5, 2024

I wonder if the speed of jar --validate as a check task would work be a blocker for general builds?

@JakeWharton
Copy link

JakeWharton commented Jun 5, 2024

Don't think so. Checks are (generally) slow!

@Sineaggi
Copy link
Author

Sineaggi commented Jun 6, 2024

I can't find any documentation, but it looks like jar --validate was added in java 17.
EDIT: here JDK-8266835

@Sineaggi
Copy link
Author

It's probably fine to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request jvm
Projects
None yet
Development

No branches or pull requests

3 participants