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