JetBrains Space Help

Publish Artifacts from a Gradle Project

Suppose you have a project that uses Gradle build tool and want to publish project artifacts to the newly created Maven repository using:

Note that publishing artifacts with the same package version is not allowed. The server will return the 409 HTTP response. The only exception: The artifacts with the SNAPSHOT prefix can be published to a repository with the enabled snaphsots support.

Publish Maven artifacts using Gradle command-line tool

To publish artifacts of a Gradle project, you should configure artifact properties, reference a repository, and specify authentication credentials. This configuration is performed in the build.gradle file.

  1. Open the project's build.gradle file.

  2. Add the reference to the Maven plugin:

    apply plugin: 'maven-publish'
  3. In the publishing section, specify the package properties (the generated package name will be groupId:artifactId). For example, we want to publish a .jar file (for the sake of length, the section content is reduced):

    publishing { publications { maven(MavenPublication) { groupId = 'org.company' artifactId = 'sample' version = "0.9-SNAPSHOT" from components.java pom { name = 'My Library' description = 'A description of my library' ... } } } }
  4. In the repositories sub-section, add the repository settings including the credentials and the URL. As it's not secure to explicitly specify credentials in build.gradle, you should use variables, which in our example are $usr and $pwd. We'll assign values to these variables in the next step.

    publishing{ ... repositories { maven { credentials { username = "$usr" password = "$pwd" } url = "https://maven.pkg.jetbrains.space/mycompany/p/projectkey/my-maven-repo" } } }
  5. You can set variable values in the gradle.properties file, which is stored locally on your machine. The default location of this file is:

    • on Windows: %HOMEPATH%\.gradle\gradle.properties

    • on Linux / macOS: ~/.gradle/gradle.properties

    Open gradle.properties and specify variable values. Here you must use the credentials of either your own Space account (using a permanent token instead of a password is strongly recommended) or a separate service account:

    usr = admin pwd = 1234

  6. That's it! Now, we can publish project artifacts by using, for example, the Gradle command-line tool or project's Gradle wrapper.

    gradlew publish

Publish Maven artifacts from JetBrains TeamCity

Before configuring TeamCity, make sure your project is configured as described in Publish Maven artifacts using Gradle command-line tool. If it's done, then all you need is to authenticate TeamCity in Space and add a gradle publish build step.

  1. Log in to your JetBrains TeamCity instance.

  2. In Administration, in project settings, open the desired build configuration.

  3. In Parameters, add two system properties for the username and the password. Note that property names must match the corresponding variable names from build.gradle. For example:

    • system.usr (if in build.gradle, you've specified username = $usr).

      Set Space username in TeamCity
    • system.pwd (if in build.gradle, you've specified password = $pwd). In Spec, type password. This will hide the password from logs, reports, and so on.

      Set Space password in TeamCity

    Finally, you should get something like this:

    Space Packages credentials in TeamCity
  4. Add a Gradle build step that runs gradle publish. No additional configuration is needed:

    Gradle build step in TeamCity

Publish Maven artifacts from Space Automation

For details, refer to the Space Automation examples.

Last modified: 28 April 2022