Home > database >  Create a Jar file with dependencies from settings.gradle
Create a Jar file with dependencies from settings.gradle

Time:12-08

I want to create a jar file which can be used by command like java -cp .\TrendAnalyzer.jar trend_detect.Main. However, I can't find a way to create a jar file from settings.gradle, not build.gradle. How can I create a jar file with dependencies from settings.gradle, which contains include etc. information.

CodePudding user response:

Add com.github.johnrengelman.shadow plugin to main module build.jar

plugins {
    // *snip*
    id 'com.github.johnrengelman.shadow' version '7.1.2'
}

application {
    // Define the main class for the application.
    mainClass = 'jaso92559.app.App'
}

jar {
    manifest {
        // Define the main class for the application.
        attributes "Main-Class": "jaso92559.app.App"
    }
}

run ./gradle shadowJar command on the path where settings.gradle exists. In app\build\libs, app-all.jar file is generated and it can be run java -jar app-all.jar.

According to https://github.com/yukihane/stackoverflow-qa/tree/main/jaso92559

  • Related