Selecting primary task results in dependency resolution failure

I get a dependency resolution failure when gradle is trying to select the primary task:

[...]
All projects evaluated.
Selected primary task 'publishToMavenLocal' from project :
Failed to get resource: GET. [HTTP HTTP/1.1 400 Bad Request: [...]

It is a multi project environment and the required artifact is published by another project before.
The configuration is like:

project A:
is publishing artifact A

project B:
requires artifact A and is publishing artifact B
because of this projectA mustRunAfter projectB

project B contains a task which extracts content from artifact A into a folder like this:

task assembleSetup(type: Copy) {
    into setupDistDir
    [...]
    with copySpec {
        into 'stuffFromA'
        from {
            zipTree(configurations.projectAConfig.singleFile)
        }
    }
}

publishing in project B is configured like this:

task zipSetup(type: Zip) {
    dependsOn assembleSetup
    from setupDistDir
    archiveName 'setup.zip'
}

publishing {
    publications {
        setupZipMaven(MavenPublication) {
            [...]
            artifact zipSetup
        }
    }
}

If I remove the dependsOn instruction from zipSetup-Task to disconnect it from assembleSetup-Task the primary task could be selected and is published to my local repository. But then, of course, the publishing of project B contains no content. :wink:

To clarify: the dependecy in project B is configured as artifact dependency like this:

depedencies {
    projectAConfig('nice.group:projectA:1.0.0.0')
}

I am sure a project dependecy would be a solution. Unfortunetally this is currently no option. Our multi project is much more complex than two projects and some projects deploy multiple artifacts in different configuration. In future we plan to ensure that one project publishes one artifact and then we can work with dependency substitution but for now it is not possible to use project dependencies.

What I don’t understand why does the publising task in project B starts dependency resolution by dependsOn. It should simply look at the mustRunAfter instruction I gave the assembleSetup-Task:

assembleSetup.mustRunAfter(':projectA:publishToMavenLocal')

I added also:

publishToMavenLocal.mustRunAfter(':projectA:publishToMavenLocal')

Which doesn’t change anything.