JetBrains Space Help

Publish Artifacts from a Maven Project

Let's assume you have a project that uses Maven as a 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 Maven command-line tool

Basically, to be able to publish artifacts of a Maven project, you should configure artifact properties, reference a repository, and specify authentication credentials. This configuration is performed in the pom.xml file.

  1. Open the project's pom.xml file.

  2. Specify package properties (the generated package name will be groupId:artifactId ):

    <groupId>org.company</groupId> <artifactId>sample</artifactId> <packaging>pom</packaging> <version>0.9-SNAPSHOT</version>

  3. In the distributionManagement section, specify repository ID (it must be a unique repository identifier) and URL:

    <distributionManagement> <repository> <id>my-repo</id> <url>https://maven.pkg.jetbrains.space/mycompany/p/projectkey/my-maven-repo</url> </repository> </distributionManagement>

  4. As it's not secure to store credentials in the VCS, we must use the local user-specific Maven settings:

    • on Windows: %HOMEPATH%/.m2/settings.xml

    • on Linux / macOS: ~/.m2/settings.xml

    Open settings.xml and place the server id (the one from Step 1) and the credentials into the servers section. 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:

    <servers> <server> <id>my-repo</id> <username>admin</username> <password>1234</password> </server> </servers>

  5. Done! Now, you can publish project artifacts by using, for example, the mvn command-line tool:

    mvn deploy

Publish Maven artifacts from JetBrains TeamCity

Before configuring TeamCity, make sure your project is configured as described in Publish Maven artifacts using Maven command-line tool. If it's done, then all you need is tell TeamCity the repository id and user credentials (the settings you store in your local settings.xml ):

  1. Log in to your JetBrains TeamCity instance.

  2. In Administration, open the project settings.

  3. In Maven Settings, upload the settings file. For example, you can use your local settings.xml as a basis. Note that, similar to Gradle, we specify variables instead of specifying the username and password explicitly. The content of the file may look like this:

    <servers> <server> <id>my-repo</id> <username>${usr}</username> <password>${pwd}</password> </server> </servers>

    TeamCity Maven Settings

    Now, we have to set these values.

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

  5. In Parameters, add two system properties for the username and the password. For example:

    • system.usr (if in Step 3, you've specified {$usr} ).

      Set Space username in TeamCity
    • system.pwd (if in Step 3, you've specified {$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
  6. Add a Maven build step that runs mvn deploy. Here you should:

    • In Goals, specify deploy.

    • In User Settings | User settings selection, choose the settings you created in Step 3.

    Maven build step in TeamCity

Publishing Maven artifacts using Space Automation

For details, refer to the Space Automation examples.

Last modified: 11 March 2021