Upload more categories of artifacts to Snapshot repo


Currently, as is expected, all our artifacts ending in “-SNAPSHOT” are uploaded to the repository specified by mavenDeployer’s snapshotRepository as documented here. We thus have to repository definitions - one regular “repository” and another “snapshotRepository” for snapshots. However we’d like to override the default handling of what constitutes a snapshot artifact and make all artifacts with “ci” in the name also be handled as snapshots.

Complicating this is the fact that our version number is not known until after the initialisation phase because we run a custom plugin that looks at the various criteria such as Git branch and command-line properties to add metadata to the version such as “ci” or “SNAPSHOT”; resulting in a final version such as “1.0.1.ci” or “1.0.1-SNAPSHOT”. This means that I can’t use an if statement during the repository definition since the version is not available (yet). How, at “afterEvaluate” time, can I override Maven repositories previously defined during the initialisation phase?



I think you mean to say configuration phase. That said, you would do so exactly the same. You can simply configure the ‘uploadArchives’ task inside an afterEvaluate { } block.

Thanks for the info Mark and, indeed, I meant during configuration phase. I figured out the root of my problem is actually that if the following conditions are true

  • Only a snapshot repository is defined
  • The artifact does not end with “-SNAPSHOT”

then it will not upload the artifact in question to the Snapshot repository (it is the only defined repository). So even if I use an if statement with the end result being that only a Snapshot repo is defined it will fail with:

Could not publish configuration 'archives'
A distributionManagement element or remoteRepository element is required to deploy

because the Maven repo code seems inherently unable to upload arbitrary artifacts to a snapshot repo. Only those with “-SNAPSHOT” in their name.

To tie this back to the original issue - how can we work around this limitation and also upload artifacts with “ci” in their name to the Snapshot repo?

This currently isn’t possible using the ‘maven’ plugin. You would have to use the new ‘maven-publish’ plugin and conditionally configure the upload repository based on the project version.

publishing {
    repositories {
        maven {
            if (project.version.endsWith('ci')) {
                url 'http://repo.foo.org/snapshots'
            } else {
                url 'http://repo.foo.org/releases'

Thanks Mark - this seems to do the trick!