Deploying to OSSRH with Gradle - Introduction

Just like Gradle can be easily configured to
consume components from the Central Repository,
it can be configured to publish to OSSRH.

Metadata and Signing

In order to deploy your components to OSSRH with Gradle, you have to meet the
requirements for your metadata in
the pom.xml as well as supply the required, signed components.

The maven plugin for Gradle
can take care of the metadata, generate the required pom.xml file as
well as take care of the deployment of the build output to the repository.
The signing plugin
allows you to get the components, created by standard Gradle tasks, signed:

apply plugin: 'maven'
apply plugin: 'signing'

Jar Files

For a typical Java project you can add a javadocJar as well as a
sourcesJar task

and hook them up into the artifacts collection together with the project
jar itself:

artifacts {
archives javadocJar, sourcesJar
}

Signing Artifacts

The defined artifacts can be signed with

signing {
sign configurations.archives
}

Metadata Definition and Upload

To prepare for the actual upload, you have to define all the metadata with
the help of the maven plugin. Group and version are set within the top
level project, while the artifactId is configured for the archiveTask.