尝试将本地android库模块发布到Artifactory

时间:2015-08-24 17:22:44

标签: android gradle artifactory

我在项目中创建了一个新的Android库模块作为测试库。它是一个简单的模块,其中一个类具有一个返回字符串的静态方法。我有Artifactory服务器在本地运行,并希望将我的Android lib /模块推送到它。我从Artifactory Web界面生成了Gradle脚本和gradle属性。我的testLib模块中的build.gradle现在看起来像这样:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'

}

/////

buildscript {
    repositories {
        maven {
            url 'http://localhost:8081/artifactory/plugins-release'
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }

    }
    dependencies {
        //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
    }
}

allprojects {
    apply plugin: "com.jfrog.artifactory"

}

artifactory {
    contextUrl = "${artifactory_contextUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    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

        }
    }
}

添加之后,我运行了./gradlew artifactoryPublish命令。它说BUILD成功。然后我转到神器网页应用程序到存储库浏览器,我查看libs-release-local,它的工件数为0.我做错了什么?

2 个答案:

答案 0 :(得分:4)

在这里找到一个有效的例子:http://jeroenmols.github.io/blog/2015/08/06/artifactory/

答案 1 :(得分:0)

您需要在Android模块的maven-publish文件中应用build.gradle插件,并在其中添加publishing { ... }块,以便模块可以发布。其次,您需要在项目的根级artifactory { ... }文件的build.gradle块中指定要发布的内容。

有关如何为Android库项目执行此操作的示例,请参阅此StackOverflow线程:

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