【问题标题】:Publish apk to Artifactory with artifactory-publish and maven-publish使用 artifactory-publish 和 maven-publish 将 apk 发布到 Artifactory
【发布时间】:2016-04-04 23:06:52
【问题描述】:

使用的插件有:“com.jfrog.artifactory”和“maven-publish”

根 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'
        }
    }
}

还有应用程序 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")
    }
}

问题是 apk 没有上传到 Artifactory,正在上传构建描述符,一切看起来都很好,只是没有 apk 工件(apk 已构建,我已经验证它存在并且命名正确并且在正确的路径)。

输出:

$ ./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

【问题讨论】:

  • 我在推测,但根项目没有 maven 发布。如果您将 artifactory{} 部分添加到应用程序 build.gradle 会怎样?
  • artifactory{} 添加到应用程序 build.gradle 没有任何区别。

标签: android gradle publish artifactory


【解决方案1】:

首先,我不确定向 Artifactory 发布 apk 是否是您想要的。您要发布到 Artifactory 的是 Android 应用程序 (apk) 还是 Android 库 (aar)?无论哪种方式,Owais Ali 都是正确的。您需要在项目的根级build.gradle 中指定要发布的内容,如下所示:

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

即便如此,我认为您可能还会遇到一些进一步的问题。有关我遇到的类似问题以及我得出的解决方案,请参阅此 Stack Overflow 线程:

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

【讨论】:

    【解决方案2】:

    你需要告诉工件插件你想要发布什么。检查 artifactory plugin 上的 Publications/publishConfigs 属性。

    【讨论】:

    • 我一直使用该链接作为模板,但由于我是一名 gradle 新手,所以我无法弄清楚如何完成此操作。
    • artifactory 闭包从根构建脚本移动到您的模块构建脚本,然后将publications('MavenPublication') 添加到您的默认值。在这种情况下,“MavenPublication”是您在“publishing.publications”闭包中指定的名称。
    • 不工作,我得到的输出:Publication named 'MavenPublication' does not exist for project ':' in task ':artifactoryPublish'. 移动插件和artifactoryPublish 关闭到应用程序项目给出了相同的消息,除了... for projects ':app' in task ... 这里一定有一个非常简单的错误.
    • 对不起,我之前的评论打错了。在您的情况下,出版物的名称是“apk”而不是“MavenPublication”(这是类型)。
    猜你喜欢
    • 2015-05-03
    • 2015-07-30
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多