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

Regression: Main-Class attribute always added to jar manifest when using application plugin #13057

Closed
ashih opened this issue May 7, 2020 · 6 comments

Comments

@ashih
Copy link

ashih commented May 7, 2020

Expected Behavior

Running gradle assemble in Micronaut project produces 2 jars (helloworld-0.1-all.jar and helloworld-0.1.jar), but only helloworld-0.1-all.jar should have a Main-Class manifest entry

helloworld-0.1.jar MANIFEST.MF:

Manifest-Version: 1.0

helloworld-0.1-all.jar MANIFEST.MF:

Manifest-Version: 1.0
Main-Class: example.Application

Current Behavior

Starting with Gradle 6.4, both jars have Main-Class manifest entries

helloworld-0.1.jar MANIFEST.MF:

Manifest-Version: 1.0
Main-Class: example.Application

helloworld-0.1-all.jar MANIFEST.MF:

Manifest-Version: 1.0
Main-Class: example.Application

Running java -jar helloworld-0.1.jar returns

Exception in thread "main" java.lang.NoClassDefFoundError: io/micronaut/runtime/Micronaut
        at example.Application.main(Application.java:24)
Caused by: java.lang.ClassNotFoundException: io.micronaut.runtime.Micronaut

Context

This stopped working with version 6.4. I know it works with 6.3.

I am creating a general purpose build pipeline for gradle projects. The pipeline involves installing the latest gradle version onto a clean Ubuntu image and building a gradle application. This build pipeline is used for Google's open sourced buildpacks. In this buildpack, we run gradle assemble then search in build/libs for a single jar with a Main-Class manifest entry to determine which jar to run. When multiple jars have Main-Class manifest entries, we error.

Steps to Reproduce

Using this gradle sample: https://github.com/micronaut-projects/micronaut-examples/tree/master/hello-world-java

  1. Run gradle assemble with Gradle version 6.4
  2. Extract data in jars in build/libs (should be the two listed above)
  3. Notice they both have Main-Class manifest entries in 6.4 (located at META-INF/MANIFEST.MF), but only one has the manifest entry when built with 6.3.

Your Environment

This is running inside a minimal Ubuntu 18.04 image with Java 11 JDK.
Build scan URL:
https://gradle.com/s/bkpeawim6ffns
(Have not received email to activate but will when I receive it)

@ljacomet
Copy link
Member

Thanks for the report.

This is indeed a change that was done as part of the Java Module System support. And it probably should not have been done in a minor.

Looking at options to handle this, will update on this issue.

@ljacomet
Copy link
Member

Note that a workaround is available by doing:

tasks.named("jar").configure {
    manifest.attributes.remove("Main-Class")
}

@ashih
Copy link
Author

ashih commented May 12, 2020

Thanks for looking into this. Does this mean it is an intended change?

@big-guy
Copy link
Member

big-guy commented May 12, 2020

No, it wasn't an intended change.

@ljacomet
Copy link
Member

This will be reverted for 6.4.1 and become an intended change in Gradle 7.0 as per #13125

@ashih
Copy link
Author

ashih commented May 15, 2020

Is there any way to support JPMS while also ensuring that this regression does not happen in 7.0? This output is odd for anyone working with micronaut.

@big-guy big-guy changed the title Multiple jars with Main-Class Manifest entries in Micronaut Project after 6.4 upgrade Regression: Main-Class attribute always added to jar manifest when using application plugin May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants