Gradle Artifactory Plugin - 如何从项目中的多个模块发布工件? [英] Gradle Artifactory Plugin - How to publish artifacts from multiple modules in a project?

查看:35
本文介绍了Gradle Artifactory Plugin - 如何从项目中的多个模块发布工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,它有一个 SharedCode(Java)模块,其次是一个 Android(Android 库)模块,它依赖于 SharedCode模块.我想发布来自 SharedCode 模块的 jar 工件和来自 Android 模块的 aar 工件.我不知道如何编写我的 build.gradle 文件,以便在 artifactoryPublish 任务运行时两个模块都发布到 Artifactory.目前只有 SharedCode 模块将其工件发布到 Artifactory.

I have a project which has a SharedCode (Java) module and secondly an Android (Android library) module which depends on the SharedCode module. I want to publish a jar artifact from the SharedCode module and an aar artifact from the Android module. I can't figure out how to compose my build.gradle files so that both modules publish to Artifactory when the artifactoryPublish task is run. At the moment only the SharedCode module publishes its artifact to Artifactory.

我的 build.gradle 文件如下.请注意,我的 build.gradle 文件的 maven-publish 方面似乎是正确的,因为当我运行 publishToMavenLocal 任务时,我看到了来自我本地 Maven 文件夹中的两个模块(即 '~/.m2/repository').

My build.gradle files are as below. Note that the maven-publish aspect of my build.gradle files appears to be correct because when I run the publishToMavenLocal task I see the artifacts from both modules in my local Maven folder (i.e. '~/.m2/repository').

首先,我的SharedCode模块中的build.gradle文件如下:

Firstly, the build.gradle file in my SharedCode module is as follows:

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

group = "${projectGroupId}"
version = "${projectVersionName}"

dependencies {
    compile 'com.google.guava:guava:18.0'
}

publishing {
    publications {
        SharedCode(MavenPublication) {
            groupId "${projectGroupId}"
            artifactId 'SharedCode'
            version "${projectVersionName}"
            from components.java
        }
    }
}

artifactory {
    contextUrl = "${artifactory_url}"
    publish {
        repository {
            repoKey = 'libs-release-local'
            username = "${artifactory_username}"
            password = "${artifactory_password}"
        }
        defaults {
            publications('SharedCode')
            publishArtifacts = true
            properties = ['qa.level': 'basic', 'dev.team': 'core']
            publishPom = true
        }
    }
}

其次,我的Android模块中的build.gradle文件如下:

Secondly, the build.gradle file in my Android module is as follows:

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

group = "${projectGroupId}"
version = "${projectVersionName}"

android {
    // android stuff here...
}

dependencies {
    compile project(':SharedCode')
}

publishing {
    publications {
        Android(MavenPublication) {
            groupId "${projectGroupId}"
            artifactId 'Android'
            version "${projectVersionName}"
            artifact "$buildDir/outputs/aar/Android-release.aar"
        }
    }
}

artifactory {
    contextUrl = "${artifactory_url}"
    publish {
        repository {
            repoKey = 'libs-release-local'
            username = "${artifactory_username}"
            password = "${artifactory_password}"
        }
        defaults {
            publications('Android')
            publishArtifacts = true
            properties = ['qa.level': 'basic', 'dev.team': 'core']
            publishPom = true
        }
    }
}

如果我在根、项目级别或 SharedCode 模块级别运行 artifactoryPublish 任务,那么我会看到如下输出:

If I run the artifactoryPublish task at the root, project level or at the SharedCode module level then I see output as follows:

18:23:38: Executing external task 'artifactoryPublish'...
Publication named 'SharedCode' does not exist for project ':Android' in task ':Android:artifactoryPublish'.
:SharedCode:generatePomFileForSharedCodePublication
:SharedCode:artifactoryPublish
Deploying artifact: http://localhost:8081/artifactory/libs-release-local/com/mycompany/sdk/SharedCode/0.0.2/SharedCode-0.0.2.jar
Deploying artifact: http://localhost:8081/artifactory/libs-release-local/com/mycompany/sdk/SharedCode/0.0.2/SharedCode-0.0.2.pom
Deploying build descriptor to: http://localhost:8081/artifactory/api/build Build successfully deployed.
Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/client-sdk/1457375019604

BUILD SUCCESSFUL

请注意,在这种情况下,仅发布了 SharedCode 工件.

Note that only the SharedCode artifact is published in this case.

如果我在 Android 模块级别运行 artifactoryPublish 任务,那么我会看到如下输出:

If I run the artifactoryPublish task at the Android module level, then I see output as follows:

18:25:25: Executing external task 'artifactoryPublish'...
Publication named 'SharedCode' does not exist for project ':Android' in task ':Android:artifactoryPublish'.
:Android: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/client-sdk/1457375127269

BUILD SUCCESSFUL

请注意,在这种情况下没有发布任何工件.

Note that no artifacts are published in this case.

推荐答案

通过他们 github 存储库上的 artifactory 多项目示例,似乎只有根项目需要有一个 artifactory{...} 配置部分,而不是像您在每个子项目中所做的那样.

Going by artifactory multi-project examples on their github repo, it would seem that only the root project needs to have an artifactory{...} configuration section as opposed to in every sub-project as you have done.

此外,当您在根项目中声明 publications('SharedCode') 时,artifactory 插件似乎在每个子项目中寻找名为 sharedCode 的出版物.

Moreover when you declare publications('SharedCode') in the root project, artifactory plugin seems to be looking for a publication called sharedCode in every subproject.

我会尝试:

  • 从 android build.gradle 中删除 artifactory{...} 部分

将 android 出版物重命名为 sharedCode(或者在两个项目中使用更通用的名称)

Rename the android publication to sharedCode as well (or something more generic in both projects)

这篇关于Gradle Artifactory Plugin - 如何从项目中的多个模块发布工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆