-
Notifications
You must be signed in to change notification settings - Fork 16
Publishing
Publishing artifacts to a Maven repository with bld is straight forward.
First, make sure that your build file is extending Project
, so that the publishing operation is available:
public class MyLibraryBuild extends Project {
// ...
}
Then you'll need to set up one or more repository to publish your artifact to.
For example, to publish to Maven Central, add the following to your build file:
publishOperation()
.repository(CENTRAL_RELEASES)
.withCredentials(
property("centralUser"),
property("centralPassword"));
NOTE: Sonatype has sunset OSSRH and replaced it with Central Publisher Portal.
In order to migrate from OSSRH to Central Publish Portal, you merely need to replace the repositories
SONATYPE_RELEASES
withCENTRAL_RELEASES
, andSONATYPE_SNAPSHOTS
withCENTRAL_SNAPSHOTS
. The rest of your build sources can stay the same.
bld
uses the Portal OSSRH Staging API with the repositoryCENTRAL_RELEASES
. When publishing a release,bld
will automatically close the staging repository so that your new deployment is ready for publication through your portal deployments.Old OSSRH tokens don't work with Central Publisher Portal, a new user token needs to be generated in order for your publications to succeed.
Next, you'll need to provide some information about your artifact, developer(s), license and scm, if any. For example:
publishOperation()
// ...
.info(new PublishInfo()
.groupId("com.example")
.artifactId("my-cool-library")
.name("My Library")
.description("My Library is very cool!")
.url("https://github.com/johndoe/mylibrary")
.developer(new PublishDeveloper()
.id("johndoe")
.name("John Doe")
.email("[email protected]")
.url("https://doe.com/"))
.license(new PublishLicense()
.name("The Apache License, Version 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0.txt"))
.scm(new PublishScm()
.connection("scm:git:https://github.com/johndoe/mylibrary.git")
.developerConnection("scm:git:[email protected]:johndoe/mylibrary.git")
.url("https://github.com/johndoe/mylibrary"))
.signKey(property("signKey"))
.signPassphrase(property("signPassphrase")));
In the examples above, you'll notice that the repository and signing credentials are set via properties. Be sure to read the section on how bld can be used to handle sensitive data.
Finally, to publish your artifact, use the following command:
./bld publish
NOTE: If you're not ready to publish your artifacts publicly, you can always use
./bld publish-local
and your project will be published to your local Maven repository.
Next learn more about Kotlin Support