Rolando
Rolando

Reputation: 62704

How to make a runnable jar with gradle that depends on three jars?

I have a java program with a simple main class that depends on libraries a.jar, b.jar, c.jar. How do I make it such that I can create a runnable jar file with all those jars properly packaged?

I know in the jar task, you need to include:

apply plugin: 'java'
apply plugin:'application'

repositories {
    mavenCentral()
}
jar {
    manifest {
        attributes 'Main-Class': 'com.foo.bar.MainClass'
    }
}

But do not know what to do with the three external jars that my code uses.

Upvotes: 3

Views: 95

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123996

The easiest way is to merge the dependency Jars into the main Jar:

jar {
    from "path/to/jar1", "path/to/jar2"
}

Or, if the Jars are retrieved from a Maven/Ivy repository:

jar {
    from configurations.runtime
}

Alternatively, you can use a plugin such as gradle-onejar, which covers more use cases.

Upvotes: 2

Related Questions