Skip to content

Publish Maven artifacts to CloudRepo

Maven publishes to CloudRepo like it publishes to any repository: the repository’s address goes in pom.xml, the credential goes in settings.xml, and mvn deploy uploads your artifact. To use what you published, see Pull Maven artifacts.

  • A Maven repository. If you have none, create one.
  • A repository token that reaches it, with Download and publish packages. A Download packages token can pull but not publish: CloudRepo answers its mvn deploy with 403. See Repository tokens to create one. Your username is the email address of the account that created the token, and your password is the token.
  • Your repository’s URL, https://<organization>.mycloudrepo.io/repositories/<repository>. Your organization’s name is the first part of your CloudRepo host, and the repository’s name is the one the admin portal shows. The repository’s Connection Settings show the URL with your names filled in.

Used on this page only, never saved. Never enter a token or password here.

1. Put the credential in ~/.m2/settings.xml. The <id> is a name you choose, and the repository in your pom.xml must use the same one. ${env.CLOUDREPO_TOKEN} reads the token from an environment variable, so the file holds no token. Export the variable in the shell that runs Maven, or in your CI’s secret store.

~/.m2/settings.xml
<settings>
<servers>
<server>
<id>cloudrepo</id>
<username>you@example.com</username>
<password>${env.CLOUDREPO_TOKEN}</password>
</server>
</servers>
</settings>

2. Name the repository in pom.xml. The <distributionManagement> repository is where mvn deploy publishes. Put it in a parent POM if you have one, so a project states it once.

pom.xml
<distributionManagement>
<repository>
<id>cloudrepo</id>
<url>https://your-org.mycloudrepo.io/repositories/your-repo</url>
</repository>
</distributionManagement>

3. Publish. Run this in the directory of your pom.xml:

Terminal
mvn --batch-mode deploy

Expected: Maven prints Uploading to cloudrepo: and Uploaded to cloudrepo: for the POM, the JAR and maven-metadata.xml, and ends with BUILD SUCCESS.

4. Check that it landed. Fetch the POM you published. Put the credential in ~/.netrc and ask curl to read it, and keep the file readable by you alone (chmod 600 ~/.netrc).

~/.netrc
machine your-org.mycloudrepo.io
login you@example.com
password YOUR_REPOSITORY_TOKEN
Terminal
curl --netrc --fail --remote-name \
https://your-org.mycloudrepo.io/repositories/your-repo/com/example/docs/docs-maven/1.0.0/docs-maven-1.0.0.pom

Put your artifact’s group (dots become slashes), name and version in the path. You can also see the artifact in the repository in the admin portal. A Hosted Maven repository opens on Packages, where the artifact is listed by its coordinate. Select Files to browse to the version.

The maven-releases repository with Files selected, its file browser at com/example/docs/docs-maven/1.0.0: docs-maven-1.0.0.jar and docs-maven-1.0.0.pom, with their checksum files.

A version that ends in -SNAPSHOT can be published again and again, so your CI can deploy each build. A release version, one that does not end in -SNAPSHOT, is published once: CloudRepo refuses a second publish to the same coordinate with 409, and the artifact already there stays as it is. Maven rewrites maven-metadata.xml and its checksum files on every publish, so the refusal does not apply to them. The setting behind this, Overwrite Protection, is on by default; see Overwrite Protection for every file it covers.

To accept republished releases, turn Overwrite Protection off in the repository’s settings. A build that resolved a version yesterday can then get different bytes today.

A snapshot is a version that ends in -SNAPSHOT. Each deploy of a snapshot version writes a new build, so a project that deploys often collects many builds of the same snapshot. A release version has one build.

In the repository’s settings, turn on Snapshot Cleanup and set Snapshots to keep per version from 1 to 10. This sets how many builds to keep for each group, artifact and snapshot version.

Saved. Automatic snapshot cleanup isn’t running yet, so nothing is deleted.

Maven prints only the status line, such as status code: 409, reason phrase: Conflict (409), and not the explanation CloudRepo sends with it.

  • 401 Unauthorized. The credential was refused. A token that is expired or revoked fails the same way. Use the email address of the account that created the token as the username, and the token as the password. The Repository Tokens page in the admin portal shows the token’s status. If you’ve set up a second factor, your portal password no longer works for builds. Use a repository token instead.
  • 403 Forbidden. The token cannot publish here: it has Download packages access, or it does not include this repository. A token only works for the repositories selected when it was created. Use a Download and publish packages token that includes this repository.
  • 405 Method Not Allowed. The URL is a group’s or a Proxy repository’s. Neither stores what you publish. Name a Hosted repository in <distributionManagement>.
  • 409 Conflict. This release version is already in the repository. Publish a new version, or use a -SNAPSHOT version while you iterate.
  • 413 Request Entity Too Large. A file is over 50 GB (50,000,000,000 bytes), the most a single file can be. Keep each file at or under 50 GB.

More: Repository tokens, for every client’s credential; Publish Gradle artifacts, if Gradle builds your project; and Pull Maven artifacts, for resolving dependencies, proxies and groups.

View as Markdown