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

Adil Hussain

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.

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').

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

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

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

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

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.

RaGe

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.

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

I would try:

  • Remove the artifactory{...} section from the android build.gradle

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to publish and use gradle plugin with dependencies on local project?

How to script Gradle in order to publish shadowjar into Artifactory

How to publish proguard JAR as Maven Artifact using Gradle Publish Plugin

How do I generate maven-metata.xml with maven-publish and the artifactory-gradle-plugin?

How to publish multiple NPM modules from a single node project?

Gradle Artifactory plugin error

Jenkins Artifactory plugin - grabbing latest artifacts

How to publish artifacts separately for each project in solution from VSTS CI pipeline?

Gradle Artifactory Plugin - How to auto-deploy spring boot fatjar

How to copy artifacts from upstream project in Jenkins?

Use of Maven publish plugin for Android project in Gradle 5

How to trigger Artifactory build retention from gradle

How to restore/recover deleted artifacts from JFrog artifactory

How to publish modules on Artifactory with their versions, dependencies and a custom artifactId

How to publish Travis CI artifacts to GitHub Release from several jobs

Publish multiple Gradle modules in one Maven artifact

How can I publish a specific subset of artifacts in Gradle

Configure Gradle's Artifactory plugin to publish to release or snapshot repository

How to send Artifactory publish credentials from buildscript without hardcoding them?

How to publish custom artifacts to Artifactory from TeamCity?

Download artifacts archive from Artifactory

How to use gradle Artifactory plugin in gradle subproject

How to upload artifacts to maven central with gradle and the maven plugin via a proxy

gradle plugin 3.0 not building the artifacts

How do I publish Gradle plugins to Artifactory?

Trigger a Gradle task from a custom java plugin automatically for all modules of the project

How to publish and download artifacts from multiple jobs into one location on pipeline?

How to access extra properties from project build.gradle in modules

Gradle how to publish a gradle-plugin to maven central

TOP Ranking

HotTag

Archive