Gradle Packaging Java Projects

Source: Internet
Author: User

Reprint Address: http://www.gfzj.us/series/gradle/2014/12/12/gradle%E5%B0%8F%E7%B3%BB%E5%88%97 (4)--gradle%e6%89%93%e5%8c% 85java%e9%a1%b9%e7%9b%ae.html

As an example of the example in the Gradle small series, here are two ways to publish a Java project Gradle:

Fat jar Mode

This method takes resources such as the jar package that the project relies on into an executable jar package, and the resulting jar is large.

In the Gradletest project, we package the SubPro1, so we need to modify the Build.gradle file under SubPro1:

jar {from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }manifest {attributes ‘Main-Class‘: ‘hello.HelloWorld‘}}dependencies {compile project(":SubPro2")}

The above configuration adds the jar Task,from is the dependency of SubPro1 packaging, manifest generates the configuration information to main, that is, the Helloworld.java under the package Hello is the project portal

The gradle build jar package can be generated by executing commands at the root of the project Gradletest

Using the Gradle application plugin

Fat jars are not always a suitable choice, such as the need to rely on the separation from the jar, the software can be started in *nix and Windows Script, and so on. Then use the Gradle application plugin to do it.

In the Gradletest project, we made the following modifications to the SubPro1 build.gradle: Delete the jar task, add the application plugin, and configure the main class (the value of the Mainclassname is set). The result of the modification is as follows:

apply plugin: ‘application‘mainClassName = ‘hello.HelloWorld‘dependencies {compile project(":SubPro2")}

The application plugin provides 5 tasks to implement the project's release, namely

run、startScript、installApp、distZip、distTar

Assuming that you use Distzip, run the command in the Gradletest directory gradle distZip , in SubPro1 build/distributions, you can see the zip file that contains the bin and Lib folders, a software startup script under the bin, Lib is the software jar package and all its dependencies.

Gradle Packaging Java Projects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.