3

I'm trying to build a Kotlin application but, even with successfully build, I face with the error bellow. What I'm doing wrong?

▶ java -jar build/libs/app-0.1.jar
22:10:02.122 [main] INFO  io.micronaut.runtime.Micronaut - No embedded container found. Running as CLI application

Here is my build status:

▶ ./gradlew assemble

BUILD SUCCESSFUL in 3s
14 actionable tasks: 1 executed, 13 up-to-date

That is the part of my gradle.build file:

apply from: "dependencies.gradle"
apply from: "protobuf.gradle"

version "0.1"
group "app"
mainClassName = "app.Application"

dependencies {
    compile "ch.qos.logback:logback-classic:1.2.3"
}

jar {
    manifest {
        attributes "Main-Class": mainClassName
    }
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}
Italux
  • 95
  • 1
  • 2
  • 9

2 Answers2

2

I had a similar issue:

  1. I was able to run code from IDE, but failed to run Docker container with the app
  2. And had compile 'io.micronaut:micronaut-http-server-netty:1.1.0' in my build.gradle.

Also I was using shadowJar plugin and there was the issue. Adding:

shadowJar {
    mergeServiceFiles()
}

solved the problem. It transforms entries in META-INF/services resources into a single resource. My shadowed jar file contained a lot of entries in this folder.

peppered
  • 688
  • 11
  • 15
  • I am facing the same issue. I am trying to replace 'shadowJar()` with `jar` task of `java` plugin. `jar` task is merging all service files in `META-INF/services` directory which is same as `shadowJar` task but it is still not working. What am I missing? – thisdotnull Nov 06 '19 at 00:25
0

It is difficult to say for sure without seeing the project but one thing that could cause that issue would be not having a dependency on io.micronaut:micronaut-http-server-netty. A newly created app will have something like this in build.gradle...

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
    compile "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
    compile "io.micronaut:micronaut-runtime"
    compile "io.micronaut:micronaut-http-client"

    // Make Sure You Have This...
    compile "io.micronaut:micronaut-http-server-netty"

    kapt "io.micronaut:micronaut-inject-java"
    kapt "io.micronaut:micronaut-validation"
    kaptTest "io.micronaut:micronaut-inject-java"
    runtime "ch.qos.logback:logback-classic:1.2.3"
    runtime "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.4.1"
    testCompile "org.junit.jupiter:junit-jupiter-api:5.1.0"
    testCompile "org.jetbrains.spek:spek-api:1.1.5"
    testRuntime "org.junit.jupiter:junit-jupiter-engine:5.1.0"
    testRuntime "org.jetbrains.spek:spek-junit-platform-engine:1.1.5"
}
Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47
  • `compile "io.micronaut:micronaut-http-server-netty"` is defined on `dependencies.gradle` but even there I still facing the error. What is the best way to use shadowJar? – Italux Dec 26 '18 at 19:38
  • "What is the best way to use shadowJar?" - It depends on what you want to do with it. The default generated configuration that is created by `mn create-app someappname` works for most needs. – Jeff Scott Brown Dec 27 '18 at 03:35
  • Is there any solution for this? I have the same problem – Lobo Feb 26 '19 at 08:33
  • "Is there any solution for this?" - Yes, but the solution will depend on the specifics of what is configured wrong in the project. If you can share a sample project which demonstrates the issue, I can show you how to fix the problem in that project. – Jeff Scott Brown Feb 26 '19 at 13:43
  • @JeffScottBrown can you please help here - https://stackoverflow.com/questions/58720932/how-to-create-micronauts-fat-jar-without-shadow-plugin – thisdotnull Nov 06 '19 at 00:25
  • @bernard The question you linked there is really a separate question than the one here. – Jeff Scott Brown Nov 06 '19 at 02:46
  • Yes definitely it is. I am just trying to get more eyes on that question. – thisdotnull Nov 06 '19 at 16:51
  • I had a similar issue. I was missing runtime('netty') inside the micronaut block. This resolved the issue. micronaut { runtime('netty') //other config removed and just showing runtime config } – Arif Shaikh Jan 11 '23 at 13:23