11

I am trying to setup the artifacts (APK/aar files) build process with gradle similar to how I am used to with maven.

mvn release:prepare (Adjusts version, checks into SVN, creates the tag) 
mvn release:perform -Dgoals=deploy (Pushes the artifact to http://artifactory.XXX.local/artifactory/libs-releases-local/)

I want to be able to run the gradle commands and achieve similar results. I am using https://github.com/researchgate/gradle-release plugin for the release management (which works fine so I am good with release). But when I run the command gradlew artifactoryPublish the artifact is deployed at some other location (as if it's not respecting the repoKey in the gradle file)

D:\my-lib-android-0.0.2>gradlew artifactoryPublish ... ... [buildinfo] Not using buildInfo properties file for this build. :artifactoryPublish Deploying build descriptor to: http://artifactory.XXX.local/artifactory/api/build Build successfully deployed. Browse it in Artifactory under http://artifactory.XXX.local/artifactory/webapp/builds/my-lib-android-0.0.2/1449880830949>

BUILD SUCCESSFUL

Total time: 9.692 secs

So my question is how can I fix my setup so that the artifact is pushed to a URL similar to this:

http://artifactory.XXX.local/artifactory/libs-releases-local/com/example/my-lib-android/0.0.2/my-lib-android-0.0.2.aar

build.gradle File:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.1.2')
        classpath 'net.researchgate:gradle-release:2.3.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
plugins {
    id 'net.researchgate.release' version '2.3.4'
}

apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'
apply plugin: 'net.researchgate.release'

allprojects {
    repositories {
        jcenter()
        maven {
            url 'http://artifactory.XXX.local/artifactory/libs-releases-local'
        }
    }
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    //The base Artifactory URL if not overridden by the publisher/resolver
    publish {       
        repository {
            repoKey = "libs-releases-local"
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
    }
}

release {
    revertOnFail = false
}
task build{

}

gradle.properties File:

version=my-lib-android-0.0.3-SNAPSHOT
artifactory_user=myUserName
artifactory_password=myPasssword
artifactory_contextUrl=http://artifactory.XXX.local/artifactory
PCM
  • 873
  • 8
  • 23
  • Based on a comment (now removed) from user @RaGe, I added the plugin `id "com.jfrog.artifactory" version "3.1.0"` and also the `artifactoryPublish {.. .. }` block . But that didn't help. – PCM Dec 16 '15 at 22:13
  • You're using `maven-publish`, you should be using `artifactory-publish` instead of `artifactory` as per the answer here: http://stackoverflow.com/questions/22352475/upload-artifact-to-artifactory-using-gradle – RaGe Dec 17 '15 at 03:43
  • have you defined any `publishing{}` for your maven-publish plugin? – RaGe Dec 17 '15 at 03:44
  • Thanks! I will try that tomorrow. – PCM Dec 17 '15 at 03:47
  • Reading around a bit more, while `maven-publish` works for traditional java projects, for an android project, you might want to use [`android-maven`](https://github.com/dcendents/android-maven-gradle-plugin) – RaGe Dec 17 '15 at 04:12

2 Answers2

0

Using android-maven plugin:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.2'
        classpath 'com.github.dcendents:android-maven-plugin:1.0'
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.2.0'
    }
}

apply plugin: 'android-library'
apply plugin: 'com.jfrog.artifactory-upload'
apply plugin: 'android-maven'


configurations {
  published
}

task sourceJar(type: Jar) {
    from android.sourceSets.main.java
    classifier "sources"
}

artifactoryPublish {
    dependsOn sourceJar
}

artifacts {
    published sourceJar
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    publish {
        repository {
            repoKey = "libs-releases-local"
            username = "${artifactory_user}"
            password = "${artifactory_password}"
        }
        defaults {
            publishConfigs('archives', 'published')
            publishPom = true //Publish generated POM files to Artifactory (true by default)
            publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default)
        }
    }
}
RaGe
  • 22,696
  • 11
  • 72
  • 104
  • Now when I execute `gradlew clean` I get.. "**buildToolsVersion is not specified.**" – PCM Dec 17 '15 at 20:02
0

I usually do it with the mavenDeployer-plugin like this. Don't know if it matches your case, but I'll just leave it here.

apply plugin: 'maven'
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: 'http://arandom.nexus.com:8081/nexus/content/repositories/releases') {
                authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD);
            }
            snapshotRepository(url: 'http://arandom.nexus.com:8081/nexus/content/repositories/snapshots') {
                authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD);
            }
            pom.groupId = "groupId"
            pom.artifactId = "artifactId"
            pom.version = "${versionMajor}.${versionMinor}.${versionPatch}"
        }
    }
}

some further reading for local repos here

sschrass
  • 7,014
  • 6
  • 43
  • 62