1

I've created a micronaut application using

mn create-app my-app

It generated the project structure with a Dockerfile. The docker file is looking for the file my-app-*-all.jar to copy.

FROM openjdk:14-alpine
COPY build/libs/my-app-*-all.jar my-app.jar
EXPOSE 8080
CMD ["java", "-Dcom.sun.management.jmxremote", "-Xmx128m", "-jar", "my-app.jar"]

How do I generate the my-app-*-all.jar?

./gradlew jar is not generating the (-all) jar.

EDITED: It's only generating my-app-0.1.jar, and when I use that jar, it is giving an error. no main manifest attribute, in build/libs/my-app-0.1.jar Do I need to add any additional lines in build.gradle file?

Arun A
  • 585
  • 8
  • 14
  • With the template provided by the CLI, `./gradlew assemble` should build the jar, the task from the shadowJar will build the `*-all.jar`. Do you have any errors when running `./gradlew assemble` ? (especially because of the `new` reserved keyword from your project name ? – Airy Jul 14 '20 at 15:31
  • @Airy I am not getting any errors `./gradlew jar` and `./gradlew assemble` are both generating the jar. But when I use the jar file in Dockerfile or in local. I'm getting the error `no main manifest attribute, in build/libs/my-app-0.1.jar` – Arun A Jul 14 '20 at 16:14
  • Found that someone already asked a similar question. https://stackoverflow.com/questions/58755410/how-to-create-micronauts-fat-jar-without-shadow-plugin – Arun A Jul 14 '20 at 16:33
  • "Do I need to add any additional lines in build.gradle file?" - That is impossible to say without knowing what is currently in your `build.gradle`. – Jeff Scott Brown Jul 14 '20 at 17:47
  • @JeffScottBrown `build.gradle` is auto generated by micronaut-cli. I believe, the generated file will be the same for anyone who runs `mn create-app my-app`. I'm good for now, since `./gradlew shadowJar` did the magic. – Arun A Jul 14 '20 at 18:53
  • Which version of Micronaut are you using? – Jeff Scott Brown Jul 15 '20 at 15:37
  • @JeffScottBrown 2.0 – Arun A Jul 16 '20 at 15:14

2 Answers2

3

How do I generate the my-app-*-all.jar?

If you are using the default Gradle build config, assemble will do it.

~ $ mn --version
Micronaut Version: 2.0.0
JVM Version: 1.8.0_252
~ $ 
~ $ mn create-app my-app
| Application created at /Users/jeffscottbrown/my-app
~ $ 
~ $ cd my-app
my-app $ 
my-app $ ./gradlew assemble

BUILD SUCCESSFUL in 2s
10 actionable tasks: 10 executed
my-app $ 
my-app $ ls -l build/libs 
total 27160
-rw-r--r--  1 jeffscottbrown  staff  13473553 Jul 16 10:23 my-app-0.1-all.jar
-rw-r--r--  1 jeffscottbrown  staff      1457 Jul 16 10:23 my-app-0.1.jar
Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47
  • NOTE: `./gradlew assemble` will not generate the `*all.jar` when you use jib feature while generating the project. i.e. when you use `mn create-app my-app --features jib` – Arun A Jul 16 '20 at 21:13
-1
./gradlew shadowJar

will generate the my-app-0.1-all.jar.

NOTE: At the time of providing this answer, the shadow plugin seems to be missing when I use jib feature while generating the project. i.e. when you use mn create-app my-app --features jib shadowPlugin is not present in build.gradle file. If that is the case: Add the following lines in build.gradle

plugins {
    ...
    id "com.github.johnrengelman.shadow" version "6.0.0"
}

shadowJar {
    mergeServiceFiles()
}
Arun A
  • 585
  • 8
  • 14
  • "when you use mn create-app my-app --features jib shadowPlugin is not present in build.gradle" - That is a different scenario than was asked in the original question. The original question specifically says `mn create-app my-app`. – Jeff Scott Brown Jul 16 '20 at 19:33
  • @JeffScottBrown Sorry if it is confusing. The answer was for the original question only. I am just stating a fact and I want future readers to be aware. `mn create-app my-app` has the shadow plugin in build.gradle and the command `mn create-app my-app --features jib` doesn't have the shadow plugin in build.gradle. I'll try to edit the answer and make it as a note. – Arun A Jul 16 '20 at 20:57
  • Glad you got it figured out. All the best! – Jeff Scott Brown Jul 17 '20 at 00:43