As the best dependency management system in the Java World, MAVEN hosts the jar package to the MAVEN Central Library and then uses MAVEN dependency as a common practice for various third-party libraries in the industry, if you want to share some of the libraries you have developed with others, You can follow the same routine. Gradle can be seen as an upgraded version of MAVEN, which uses Maven's best dependency management system, but also avoids the drawbacks of Maven's build pipeline's stereotype and XML format configuration files, which can be said to be the best building tool in the Java World at the moment. Here's how you can use Gradle to deploy your own jar package to the MAVEN Central Library.
Part 1: Registering a MAVEN Central Library account for your project
In Http://oss.sonatype.orgz registered account, (note: Sonatype is MAVEN Central Library Management System), after registering to obtain the user name, password. The build script that follows will be used.
In Sonatype's Jira system, create a issue (select Project:community support-open Source Project Repository Hosting; Issue type:new project), tell Sonatype administrator that you want to host a project to Sonatype. Note that when the issue is created, only the administrator has the Change permission, so be careful not to write the wrong message
After the creation, you need to wait for Sonatype Administrator audit, generally no more than 2 working days, once the audit passed, will be marked on the issue resolved, this means that the Central library is ready to upload their own files at any time.
Part 2:maven Central Library hosting specification
To build a better Maven ecosystem, MAVEN has a very clear quality requirement for the libraries hosted on it: * The pom file for the project must contain the following elements: * If you are deploying a jar package and the jar package contains Java classes, then in addition to the jar package, You must also upload the source package for the jar package, Javadoc package, that is, you must deploy three packages. jar/-sources.jar/**-javadoc.jar. * All packages to be deployed must be signed with GPG and the public key of the signing certificate must be uploaded to the hkp://pool.sks-keyservers.net/server. More Info Maven Central requirement https://docs.sonatype.org/display/Repository/Central+Sync+Requirements
Part 3:GPG Signature
As mentioned earlier, all files that are uploaded to the MAVEN Central Library need to be signed, first of all, to download the GPG tool (https://gpgtools.org/). Mac users can download the tool with the UI directly Gpgtools Installer https://s3.amazonaws.com/gpgtools/GPGTools-20130330.dmg, after installation, generate a new certificate directly, Then send public key to key server on the line. Very simple. If you are a command-line controller, refer to gennerate GPG signature with Maven https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+ Signatures+with+maven
Part 4:gradle Script
Apply plugin: ' idea ' Apply plugin: ' java ' Apply plugin: ' maven ' Apply plugin: ' signing '//Use signing plugin to do digital signature// Defining GroupID and Version,artefactid will automatically use project name group = ' Com.thoughtworks.toggle ' version = ' 0.1.0-snapshot ' sourcecompatibility = 1.6targetCompatibility = 1.6repositories {mavencentral ();} dependencies {compile (' junit:junit:4.11 ',)}uploadarchives {repositories {mavendeployer { Digitally sign a pom file beforedeployment {mavendeployment deployment-signing.signpom (Deployment)} Specifies the Central library address to which the project is deployed, username and password are registered accounts in Part 1. Repository (URL: "https://oss.sonatype.org/content/repositories/snapshots/") {Authentication (Username:sona Typeusername, Password:sonatypepassword)}//Construct the Pom file for the project, see the specification of the Pom file in Part 2, do not omit the required fields pom.pr Oject {name Project.name packaging ' jar ' description ' Toggle is a little jav A tool to make your life EasieR When you try to use Feature Toggle in Java. ' URL ' https://github.com/xianlinbox/Toggle ' scm {URL ' Scm:[email protected]:xianlin Box/toggle.git ' connection ' scm:[email protected]:xianlinbox/toggle.git ' Develo Perconnection ' [Email protected]:xianlinbox/toggle.git '} licenses { License {name ' The Apache software license, Version 2.0 ' url ' http://www.a Pache.org/licenses/license-2.0.txt ' distribution ' Repo '}} Developers {developer {id ' xianlinbox ' name ' Liu xiannings '}}}}}//see part 2 for project Generation **.jar/**-javadoc.jar/**- Sources.jartask Javadocjar (Type:jar, dependson:javadoc) {classifier = ' Javadoc' From ' Build/docs/javadoc '}task Sourcesjar (type:jar) {classifier = ' sources ' from Sourcesets.main.allsource}ar tifacts {Archives jar Archives Javadocjar Archives sourcesjar}//Digital signature for all jar packages signing {sign configurations.ar Chives}
Part 5: Problems encountered
1. java.security.InvalidAlgorithmParameterException:the trustanchors parameter must be Non-empty
This problem only when using is the OPENJDK time only then will encounter, the reason is openjdk the package inside does not have the valid certificate, on MacOS, as long as the system library carries the cacerts to it to associate the past on the line.
CD $ (/usr/libexec/java_home-v 1.7)/jre/lib/securityln-fsh/system/library/java/support/coredeploy.bundle/contents /home/lib/security/cacerts
2.Return Code is 400
This problem has a sad process, interested can look at this issue:issue fixed process there are 2 ways to receive this error message during deployment: * Repeatedly deploying the same jar package to the MAVEN library, however, The MAVEN library is set to not allow duplicate deployments, and in the Gradle 1.0 version of Mavendeployer The problem is repeated, but the jar package is repeatedly submitted, but it has been repaired in version 1.1. * Attempt to deploy a release version of the jar package to the snapshot library. My situation is the latter, but root cause more embarrassed, because I wrote version number "0.1.0-snapshot", does not conform to MAVEN Snapshot package specification, therefore, as release version, modified to "0.1.0- SNAPSHOT, "it worked.
Deploying the jar package to the MAVEN Central Library using Gradle