Configure Gradle's Artifactory plugin to publish to release or snapshot repository

StackOverflow https://stackoverflow.com/questions/21758089

  •  11-10-2022
  •  | 
  •  

سؤال

Artifactory have two pre-defined repositories for local libraries:

  • libs-release-local: local repository for in-house libraries
  • libs-snapshot-local: local repository for in-house snapshots

The Artifactory's Gradle script generator can generate a script which uses only one repository for artifact publishing, using the artifactory plugin for Gradle.

Here is an example (only the relevant portion):

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    publish {
        repository {
            repoKey = 'libs-release-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
    }
    resolve {
        repository {
            repoKey = 'libs-release'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
    }
}

I would like to configure the plugin to use the libs-release-local or libs-snapshot-local repository based on version (i.e. if version ends with -SNAPSHOT then publish to libs-snapshot-local).

I saw this is possible using Gradle's integrated maven plugin (see snapshotRepository element of mavenDeployer in uploadArchives task), but this functionality seems not available in the artifactory plugin.

Is there any way to achieve this desired behaviour?

هل كانت مفيدة؟

المحلول

Since it's a groovy code just go ahead and use a variable, which depends on the version.

String repo = version.endsWith('SNAPSHOT') ? 'libs-snapshot-local' : 'libs-release-local'   

...

repository {
        repoKey = repo
        username = "${artifactory_user}"
        password = "${artifactory_password}"
        maven = true

    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top