Uploading artifacts of subproject to seperate maven repository

Hi,

my project looks like this root

|–appA

|–appB

|–libA

|–libB

|–libC

appA and appB use the application-plugin to create a distribution zip with the task distZip. For the libraries i wrote the tasks release and snapshot which create either a libX-version.jar or a libX-version-SNAPSHOT.jar and upload the artifacts to the first maven repository (i’ll call it mavenA). These two tasks (snapshot and release) are injected from the root project, depend on uploadArchives and set just the version number according to my needs.

Now i need the appA/B zip-files to be uploaded to another maven (mavenB), again either when calling gradle release / snapshot. I still need the jar-files of appA and appB to be uploaded to mavenA!

First i tried to add a dependency to appA’s snapshot/release-task so it depends on distZip and added the archives from distZip to the appAs artifacts. -> This way the zip-files are also uploaded to mavenA, not mavenB.

My second approach was to add the archives from appA/B’s distZip task to the root projects artifacts and write upload them from there to mavenB. I cannot figure out how to address the output of a subprojects task to add them to the root projects artifacts.

artifacts {
    archives project(':appA').distZip
}

That does not work, resulting in > Could not find property ‘distZip’ on project ‘:appA’.

How would i address the archive of a task of a subproject?

What would be the best / recommended way doing something like this?

These two tasks (snapshot and release) are injected from the root project, depend on uploadArchives and set just the version number according to my needs.

This means they run after the archive has been uploaded, at which point setting the version number won’t have much effect.

This way the zip-files are also uploaded to mavenA, not mavenB.

You need to make sure not to configure mavenA for appA/appB’s ‘uploadArchives’ tasks. Note that you can also declare additional configurations (which will automatically add additional upload tasks), or additional ‘Upload’ tasks. This is often better than using conditional logic to configure the same configuration/task differently depending on circumstances.

Hi Peter,

i didn’t mention the following:

gradle.taskGraph.whenReady {taskGraph ->
        if (taskGraph.hasTask(release)) {
         // nothing to do here
     } else {
         version = version + '-SNAPSHOT'
     }
    }

Your hint with the additional configurations solved my problem. Thank you!