1

Plugins being used are: 'com.jfrog.artifactory' and 'maven-publish'

The root build.gradle:

buildscript {
    repositories {
        maven {
            url 'http://localhost:8081/artifactory/globalmaven'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0"
    }
}

allprojects {
    repositories {
        maven {
            url 'http://localhost:8081/artifactory/globalmaven'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

group = 'com.my.package'

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

artifactoryPublish {
    clientConfig.info.setBuildName('My_special_build_name')
    clientConfig.info.setBuildNumber('1')
}

artifactory {
    contextUrl = 'http://localhost:8081/artifactory'
    publish {
        repository {
            repoKey = 'Libs-snapshot-local'

            username = project.getProperties().artifactory_user
            password = project.getProperties().artifactory_password
        }
        defaults {
            publishArtifacts = true
            publishPom = false
            publishIvy = false
        }
    }
    resolve {
        repository {
            repoKey = 'globalmaven'
        }
    }
}

And the app build.gradle

apply plugin: 'com.android.application'

version = "1.0"

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.my.package"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName version
    }
    buildTypes {
        debug {
            versionNameSuffix "-SNAPSHOT"
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:23.0.1'
}


publishing.publications {
    apk(MavenPublication) {
        groupId group
        artifactId 'MyArtifact'
        artifact("$buildDir/outputs/apk/${project.getName()}-debug.apk")
    }
}

The problem is that the apk is not uploaded to Artifactory, the build descriptor is being uploaded and everything looks good just no apk artifact (The apk is built, I've verified that it exists and is named correctly and is in the correct path).

Output:

$ ./gradlew artifactoryPublish
[buildinfo] Not using buildInfo properties file for this build.
:artifactoryPublish
Deploying build descriptor to: http://localhost:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/My_special_build_name/1

BUILD SUCCESSFUL
bmg
  • 153
  • 2
  • 8
  • I'm speculating, but the root project doesn't have a maven publication. What if you added the `artifactory{}` section to the app build.gradle? – RaGe Dec 30 '15 at 23:38
  • Adding `artifactory{}` to the app build.gradle resulted in no difference. – bmg Dec 31 '15 at 16:07

2 Answers2

2

You need to tell the artifactory plugin what it is you want published. Check the publications/publishConfigs properties on the artifactory plugin.

Owais Ali
  • 724
  • 1
  • 6
  • 14
  • I've been using that link as a template, but I'm unable to figure out how to accomplish this since I'm a gradle newbie. – bmg Dec 31 '15 at 16:08
  • Move the `artifactory` closure from the root build script to your module build script and then add `publications('MavenPublication')` to your defaults. The "MavenPublication" in this case is what you specified as your name in the "publishing.publications" closure. – Owais Ali Dec 31 '15 at 18:27
  • Doesn't work, the output I get: `Publication named 'MavenPublication' does not exist for project ':' in task ':artifactoryPublish'.` Moving the plugins and `artifactoryPublish` closure to the app project gives the same message except with `... for projects ':app' in task ...` There must be a really simple mistake here. – bmg Jan 04 '16 at 19:59
  • Sorry, had I mistyped the previous comment. The name of the publication in your case is "apk" not "MavenPublication" (which is the type). – Owais Ali Jan 05 '16 at 01:26
1

Firstly, I'm not sure publishing an apk to Artifactory is what you want. Is it an Android application (apk) or an Android library (aar) that you want to publish to Artifactory? Either way, Owais Ali is correct. You need to specify in your project's root-level build.gradle what is to be published, as follows:

artifactory {
    defaults {
        publications('apk')
        publishArtifacts = true
        publishPom = true
    }
}

Even then, I think you might still encounter some further problems. See this Stack Overflow thread for a similar problem that I encountered and the solution that I came to:

Gradle Artifactory Plugin - How to publish artifacts from multiple modules in a project?

Community
  • 1
  • 1
Adil Hussain
  • 30,049
  • 21
  • 112
  • 147