Skip to content

Publishing

Erik C. Thauvin edited this page Apr 5, 2024 · 2 revisions

Publishing to a Maven Repository

Publishing artifacts to a Maven repository with bld is straight forward.

Setup

First, make sure that your build file is extending Project, so that the publishing operation is available:

public class MyLibraryBuild extends Project {
  // ...
}

Repository

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(SONATYPE_RELEASES.location())
          .withCredentials(
              property("sonatypeUser"), 
              property("sonatypePassword"));

Artifact

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("john@doe.com")
                  .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:git@github.com:johndoe/mylibrary.git")
                  .url("https://github.com/johndoe/mylibrary"))
          .signKey(property("signKey"))
          .signPassphrase(property("signPassphrase")));

Credentials

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.

Publish

Finally, to publish your artifact, use the following command:

./bld publish

Next learn more about Kotlin Support