Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 710
Paolo Fulgoni Avatar asked Feb 13 '14 15:02

Paolo Fulgoni


People also ask

How do I publish to Artifactory?

Go to the artifact browser, select the repository you want to upload to, and hit the Set Me Up button for instructions. You can upload a file using Artifactory UI. Go to the artifact browser, select the repository you want to upload to, and hit the Upload button for instructions.

How do I publish AAR to Artifactory?

JFrog publishes a fully functional example of publishing aar to Artifactory. Here you go. Select the version of plugin you work with and look for aar example. We'll take a look and report.


1 Answers

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

    }
like image 52
JBaruch Avatar answered Oct 12 '22 21:10

JBaruch