Gradle (Kotlin)

Buildkite Package Registries provides registry support for Gradle-based Java packages (using the Maven Publish Plugin), using the Gradle Kotlin DSL. If you're using Gradle's Groovy DSL, refer to the Gradle (Groovy) page.

Once your Java source registry has been created, you can publish/upload packages (generated from your application's build) to this registry by configuring your build.gradle.kts file with the Gradle snippet presented on your Java registry's details page.

To view and copy the required build.gradle.kts configurations:

  1. Select Package Registries in the global navigation to access the Registries page.
  2. Select your Java source registry on this page.
  3. Select Publish a Java Package and in the resulting dialog's Using Gradle with maven-publish plugin section, select Gradle (Kotlin) to expand this section.
  4. Use the copy icon at the top-right of the code box to copy the Gradle code snippet and paste it into the appropriate area/s of your build.gradle.kts file.

These build.gradle.kts file configurations contain the:

  • Maven coordinates for your package (which you will need to manually configure yourself).
  • URL for your specific Java source registry in Buildkite.
  • API access token required to publish the package to this registry.

Publish a package

The following steps describe the process above:

  1. Copy the following Gradle (Kotlin) snippet, paste it into your build.gradle.kts file, and modify accordingly:

    plugins {
      `maven-publish`
      `java-library`
    }
    
    publishing {
      publications {
          create<MavenPublication>("maven") {
              // MODIFY: Define your Maven coordinates of your package
              groupId = "com.name.domain.my"
              artifactId = "my-java-package-name"
              version = "my-java-package-version"
    
              from(components["java"])
          }
      }
    
      repositories {
        maven {
          url = uri("https://packages.buildkite.com/{org.slug}/{registry.slug}/maven2/")
          authentication {
            create<HttpHeaderAuthentication>("header")
          }
    
          credentials(HttpHeaderCredentials::class) {
            name = "Authorization"
            value = "Bearer registry-write-token"
          }
        }
      }
    }
    

    where:

    • com.name.domain.my is the domain name of your Java package (in typical right-to-left order).

    • my-java-package-name is the name of your Java package.

    • my-java-package-version is the version number of your Java package.

    • {org.slug} can be obtained from the end of your Buildkite URL, after accessing Package Registries or Pipelines in the global navigation of your organization in Buildkite.
    • {registry.slug} is the slug of your Java source registry, which is the kebab-case version of this registry's name, and can be obtained after accessing Package Registries in the global navigation > your Java source registry from the Registries page.
    • registry-write-token is your API access token used to publish/upload packages to your Java source registry. Ensure this access token has the Read Packages and Write Packages REST API scopes, which allows this token to publish packages to any source registry your user account has access to within your Buildkite organization.
  2. Publish your package:

    gradle publish
    

Access a package's details

A Java package's details can be accessed from its source registry through the Releases (tab) section of your Java source registry page. To do this:

  1. Select Package Registries in the global navigation to access the Registries page.
  2. Select your Java source registry on this page.
  3. On your Java source registry page, select the package to display its details page.

If your Java source registry is an upstream of a composite registry, you can also access the Java package's details from this composite registry (listed on the Registries page) by selecting the relevant Java composite registry > from the Upstreams tab, select the relevant Java source registry, then its relevant package.

The package's details page provides the following information in the following sections:

  • Installation (tab): the installation instructions.
  • Contents (tab, where available): a list of directories and files contained within the package.
  • Details (tab): a list of checksum values for this package—MD5, SHA1, SHA256, and SHA512.
  • About this version: a brief (metadata) description about the package.
  • Details: details about:

    • the name of the package (typically the file name excluding any version details and extension).
    • the package version.
    • the source registry the package is located in.
    • the package's visibility (based on its registry's visibility)—whether the package is Private and requires authentication to access, or is publicly accessible.
    • the distribution name / version.
    • additional optional metadata contained within the package, such as a homepage, licenses, etc.

  • Pushed: the date when the last package was uploaded to the source registry.

  • Total files: the total number of files (and directories) within the package.

  • Dependencies: the number of dependency packages required by this package.

  • Package size: the storage size (in bytes) of this package.

  • Downloads: the number of times this package has been downloaded.

Downloading a package

A Java package can be downloaded from the package's details page. To do this:

  1. Access the package's details.
  2. Select Download.

Installing a package from a source registry

A Java package can be installed using code snippet details provided on the package's details page. To do this:

  1. Access the package's details.
  2. Ensure the Installation (tab) > Gradle (Kotlin) section is displayed.
  3. Copy the code snippet, paste this into the build.gradle.kts Gradle file, and modify the required values accordingly.

    You can then run gradle install on this modified script file to install this package.

This code snippet is based on this format:

repositories {
  maven {
    url = uri("https://packages.buildkite.com/{org.slug}/{registry.slug}/maven2/")
    authentication {
      create<HttpHeaderAuthentication>("header")
    }

    credentials(HttpHeaderCredentials::class) {
      name = "Authorization"
      value = "Bearer registry-read-token"
    }
  }
}

dependencies {
  implementation("com.name.domain.my:my-java-package-name:my-java-package-version")
}

where:

  • {org.slug} can be obtained from the end of your Buildkite URL, after accessing Package Registries or Pipelines in the global navigation of your organization in Buildkite.
  • {registry.slug} is the slug of your registry, which is the kebab-case version of your registry name, and can be obtained after accessing Package Registries in the global navigation > your registry from the Registries page.
  • registry-read-token is your API access token or registry token used to download packages from your Java source registry. Ensure this access token has the Read Packages REST API scope, which allows this token to download packages from any registry your user account has access to within your Buildkite organization.

    Note: Both the authentication and credentials sections are not required for registries that are publicly accessible.

  • com.name.domain.my is the domain name of your Java package (in typical right-to-left order).

  • my-java-package-name is the name of your Java package.

  • my-java-package-version is the version number of your Java package.

Installing a package from a composite registry

If your Java source registry is an upstream of a composite registry, you can install one of its packages using the code snippet details provided on the composite registry's Setup & Usage page. To do this:

  1. Select Package Registries in the global navigation to access the Registries page.
  2. Select your Java composite registry on this page.
  3. Select the Setup & Usage tab to display the Usage Instructions page.
  4. Ensure the Gradle (Kotlin) tab is displayed.
  5. Copy the relevant code snippets, and paste them into the build.gradle.kts Gradle file, modifying their values as required. Learn more about this is Configuring the build.gradle.kts Gradle file, below.

    To install packages from any of this composite registry's configured upstreams, define each of these packages in their own implementation() line within dependencies { } of your build.gradle.kts Gradle file, as you would when installing packages from a source registry, and run gradle install on this modified script file.

Configuring the build.gradle.kts Gradle file

The build.gradle.kts code snippet is based on this format:

repositories {
  // ...
  maven {
    url = uri("https://packages.buildkite.com/{org.slug}/{registry.slug}/maven2/")
    authentication {
      create<HttpHeaderAuthentication>("header")
    }
    credentials(HttpHeaderCredentials::class) {
      name = "Authorization"
      value = "Bearer registry-read-token"
    }
  }
}

where:

  • {org.slug} can be obtained from the end of your Buildkite URL, after accessing Package Registries or Pipelines in the global navigation of your organization in Buildkite.
  • {registry.slug} is the slug of your registry, which is the kebab-case version of your registry name, and can be obtained after accessing Package Registries in the global navigation > your registry from the Registries page.
  • registry-read-token is your API access token or registry token used to download packages from your Java composite registry. Ensure this access token has the Read Packages REST API scope, which allows this token to download packages from any registry your user account has access to within your Buildkite organization.

    To avoid having to store the actual token value in this file (and mitigate its exposure to continuous integration environments), you can reference it using an environment variable. For example, if you set this token value in the environment variable REGISTRY_READ_TOKEN, like:

    export REGISTRY_READ_TOKEN="YOUR-ACTUAL-TOKEN-VALUE"
    

    you can reference this in the value field above as:

    value = "Bearer ${System.getenv('REGISTRY_READ_TOKEN')}"
    

If you have added the official public registry to this Java composite registry, ensure that any references to the default mavenCentral() repository (in your build.gradle.kts or other relevant .gradle.kts files) have been removed, since Buildkite Package Registries itself handles the connection to the Maven Central repository through your Java composite registry.