How can I use Gradle to build a jar with required

2019-08-13 03:19发布

In Eclipse, you can create a project jar with its required dependencies in an adjacent sub-folder by doing ...

  • Export->Java->Runnable JAR file

  • Select Library handling option: Copy required libraries into a sub-folder next to the generated JAR

Is there a way to do this with the Gradle?

PS: I am working on gradle 2.2.1

1条回答
我想做一个坏孩纸
2楼-- · 2019-08-13 03:59

You can create a Gradle task for copying, like so:

task copyLibs(type: Copy) {
    from('path/to/dir/with/lib/jars/')
    into('path/to/subfolder/next/to/generated/jar/')
    include('names.jar','of.jar','jars.jar','to.jar','copy.jar')
}

copyLibs.dependsOn(build)

Edit:

task combinedJar(type: Jar) {
   from zipTree("path/to/generated.jar")
   from "path/to/subfolder/next/to/generated/jar/"
}

combinedJar.dependsOn(copyLibs)

Run via gradlew copyLibs. You can make the task depend on the build task that builds your project.

Note that you may have to also create the path/to/subfolder/next/to/generated/jar/ in the task.

查看更多
登录 后发表回答