3

What started as a roadblock to setup a new Micronaut project with corporate repo, is now more about curiosity of how Embedded server is bootstrapped. I have a Micronaut CLI generated project with com.github.johnrengelman.shadow gradle plugin which works fine when I run the jar using-

$ java -Dmicronaut.environments=E1 -jar build/appBundle/app.jar

build.gradle-

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

...

shadowJar {
    mergeServiceFiles()
}

When I replace shadow plugin/task with jar task and java plugin, then I am able to create an executable fat-jar , but it fails with following error-

$ java -Dmicronaut.environments=E1 -jar build/appBundle/app.jar
16:12:22.662 [main] INFO  i.m.context.env.DefaultEnvironment - Established active environments: [E1]
16:12:22.863 [main] INFO  io.micronaut.runtime.Micronaut - No embedded container found. Running as CLI application

build.gradle-

plugins {
  id "java"
}

...

jar {
  manifest {
    attributes "Main-Class": "foo.bar.someclass"
  }

  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
  }
}
  1. What I would like to understand is how the embedded server bean is getting injected with shadow plugin but not otherwise?
  2. How to create a fat-jar with embedded Netty server and without using com.github.johnrengelman.shadow gradle plugin?
thisdotnull
  • 812
  • 1
  • 7
  • 20
  • Isn't it exactly that plugin that creates the fat-jar? So without a Plugin that create a fat-jar, you must do it yourself inside Gradle the hard and ugly way (building yourself a JAR with correct manifest, with logic for overwriting classes,etc.). It's a bit more that just put all libs extracted in the jar – Serverfrog Nov 25 '19 at 11:09
  • This question really has nothing to do with Micronaut. You should explain your reasoning for not using the shadow plugin otherwise it doesn't make sense. – James Kleeh Nov 27 '19 at 06:43
  • @Serverfrog Yes, `shadow-jar` works fine with micronaut. Other approach to create a fat-jar is by using `jar` task of `java` plugin in gradle. It's mentioned up there if you read the entire question. I am trying to understand why the latter isn't working for micronaut while it works for a simple java app. – thisdotnull Dec 02 '19 at 22:46
  • 1
    @JamesKleeh Yes it might not be a micronaut problem. I am trying to understand why `jar` task of `java` gradle plugin isn't working for micronaut while it works for a simple java app. – thisdotnull Dec 02 '19 at 22:48
  • shadow jar combines your code and your dependencies into a single jar. If you just use jar you have to add your dependencies to the classpath when running the app via java -jar – James Kleeh Dec 03 '19 at 15:24
  • resulting `fat-jar` contains all the classes and it is executable. When Micronaut entry point is invoked, it doesn't find any embedded server in context which I am guessing should be `io.micronaut.http.server.netty.NettyHttpServer`, although I can see this class file in packaged jar. – thisdotnull Dec 04 '19 at 23:32

0 Answers0