5

I'm stuck with integrating artifactory 3.0.1 plugin with Gradle. I'm using Android Studio 1.0 so I'm guessing that I'm on Gradle 2.0. Any examples on publishing to artifactory using the 3.0.1 plugin would be highly helpful.

Thanks in advance

Jani
  • 1,400
  • 17
  • 36
  • [A private Maven repository for Android in 30 min](https://jeroenmols.com/blog/2015/08/06/artifactory/) Tried with latest Android Studio 3.3, worked like a charm – Bill Hoo Jan 29 '19 at 05:10

2 Answers2

4

Publishing to Artifactory is just a configuration task. You just need to configure two plugins, com.jfrog.artifactory and maven-publish, and run artifactoryPublish Gradle's task. But... let's explain it by code, to ease copypasting :·)

At your library's build.gradle:

apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

publishing {
    publications {
        aar(MavenPublication) {
            groupId 'com.fewlaps.something' //put here your groupId
            artifactId 'productname' //put here your artifactId
            version '7.42.0' //put here your library version

            // Tell maven to prepare the generated "*.aar" file for publishing
            artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
        }
    }
}

artifactory {
    contextUrl = 'https://your-artifactory-host.com/artifactory'
    publish {
        repository {
            repoKey = "libs-release-local"
            username = "username"
            password = "password"
        }
        defaults {
            // Tell the Artifactory Plugin which artifacts should be published to Artifactory.
            publications('aar')
        }
    }
}

And then, run ./gradlew artifactoryPublish

In addition, if you want to upload the artifact everytime you push a tag to GitHub, add this code to your .travis.yml

deploy:
  - provider: script
    script: ./gradlew artifactoryPublish
    skip_cleanup: true
    on:
      tags: true

If it doesn't launch a build for the tag when you push a tag to GitHub, check that you're building vX.X.X tags on Travis:

# Build only master and "vX.X.X" tags to prevent flooding Travis machines
branches:
  only:
    - master
    - /^v\d+\.\d+\.\d+$/
Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
  • 1
    Since Android Gradle plugin version 3.6, you can configure a Maven publication simply with `from components.release`. Outside of that, this answer remains accurate. See https://developer.android.com/studio/build/maven-publish-plugin. – Big McLargeHuge May 07 '20 at 16:23
1

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.

JBaruch
  • 22,610
  • 5
  • 62
  • 90
  • 2
    Yes I've tried it and it works great for the old plugin (2.3) but not the 3.0.1 – Jani Dec 29 '14 at 08:06
  • We'll take a look and report. – JBaruch Dec 29 '14 at 12:29
  • 1
    I managed to configure the plugin and now the publishing seems to work. However I'm unable to resolve the published artifact through gradle. maven { url "http://localhost:8081/artifactory/gradle" credentials { username = 'admin' password = 'password' } } . any idea ? – Jani Dec 29 '14 at 13:13
  • You need to manage the resolve through the Artifactory plugin: artifactory{ . . . resolve { repository { repoKey = 'libs-release' username = artifactory_user password = artifactory_password } } } – liorha Dec 29 '14 at 14:05
  • 1
    Isn't it possible to resolve without the artifactory plugin ?. As a gradle compile dependency ? – Jani Dec 29 '14 at 14:54
  • I resorted in using Apache Archiva instead – Jani Jan 08 '15 at 10:35
  • Here go custom DSL, CI server integration and tons of other features. – JBaruch Jan 08 '15 at 10:38
  • Yup, I can't get the gradle artifactory plugin to work with an android library either. Example at https://github.com/JFrogDev/project-examples/tree/master/gradle-android-aar is now outdated a few versions behind the latest android gradle plugin. – McNinja Feb 19 '15 at 02:21
  • Link in the answer results in 404 (page not found) error. – Adil Hussain Mar 04 '16 at 15:48