Use Gradle to package Maven libraries into jars

Source: Internet
Author: User

The project needs to package Dropwizard (Java restful service) and Derby (Lightweight database) into jars and then provide them for use in other projects. since Dropwizard did not provide the jar-release version, a Gradle build script was written to package Dropwizard and Derby in the Maven library into a jar package and then add it to the target project.

Script code:

Apply plugin: ' java 'Project.ext {//Project Title nametitle = ' Dropwizardderby '//Project name prefixBaseName = ' Dropwizardderby '//Project version InformationVersion = ' 0.1.0 '//Dropwizard versiondropwizardversion = ' 1.0.6 '//Derby versionderbyversion = ' 10.13.1.1 '}task Release (Type:jar) {//Manifest PropertiesManifest {attributes' Implementation-title ': project.ext.title, ' implementation-version ': Project.ext.version}//Jar Package NameBaseName = Project.ext.baseName +project.ext.version//Packaging DependenciesFrom {configurations.compile.collect {it.isdirectory ()?It:ziptree (IT)}} With Jar}//Maven Libraryrepositories {mavencentral ()}//Dependency SettingsDependencies {compile (' Io.dropwizard:dropwizard-core: ' +Project.ext.dropwizardVersion,' Io.dropwizard:dropwizard-hibernate: ' +Project.ext.dropwizardVersion,' Io.dropwizard:dropwizard-migrations: ' +Project.ext.dropwizardVersion,' Io.dropwizard:dropwizard-auth: ' +Project.ext.dropwizardVersion,' Org.apache.derby:derby: ' +project.ext.derbyVersion)}

How to use:

1, install Gradle (I use 2.1.0 version) and add environment variables

2. Create the script in any directory

3. Implementation

Gradle Cleangradle Release

4. Then if it works, the generated jar package will be found in Build/libs.

5, and then in other projects to rely on the jar, in theory this script can also be applied to other MAVEN library packaging, once again provide only one idea, you can modify

That's all, thanks for reading, if there is a better way to welcome comments to exchange!

Use Gradle to package Maven libraries into jars

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.