Unable to find zip artifact in composite build if java plugin is applied

I have a Gradle project which creates a zip artifact. I define the artifact via artifacts.add('default', zipTask) . I add this project to another project via includeBuild and use the zip as dependency ( dependencies { myConfiguration 'org.example:testA:+@zip' } ). So far so good. It works.

The problem start when I add plugin java to the first project. For some reason it prevents Gradle from finding the zip artifact. The error is:

Execution failed for task ':doubleZipTask'.
> Could not resolve all files for configuration ':myConfiguration'.
   > Could not find testA.zip (project :testA).

Why? How to fix it?

Complete example:

Project testA

settings.gradle :

rootProject.name = 'testA'

build.gradle :

plugins {
    id 'base'
    // Uncomment the line below to break the zip artifact
    //id 'java'
}

group = 'org.test'
version = '0.0.0.1_test'

task zipTask(type: Zip) {
    from './settings.gradle' // just so the zip isn't empty
}

def myArtifact = artifacts.add('default', zipTask)

Project testB

settings.gradle :

rootProject.name = 'testB'

// This line may be commented out in some cases and then the artifact should be downloaded from Maven repository.
// For this question it should be always uncommented, though.
includeBuild('../testA')

build.gradle :

plugins {
    id 'base'
}

configurations {
    myConfiguration
}

dependencies {
    myConfiguration 'org.test:testA:0.0.0.+@zip'
}

task doubleZipTask(type: Zip) {
    from configurations.myConfiguration
}

After I’ve added some diagnostic code at the end of the build.grade :

configurations.default.allArtifacts.each() {
    println it.toString() + ' -> name: ' + it.getName() + ', extension: ' + it.getExtension()
}

I’ve got the following result in the the version with java plugin:

ArchivePublishArtifact_Decorated testA:zip:zip: -> name: testA, extension: zip
org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact@2c6aaa5 -> name: testA, extension: jar

Although, I’m not sure if an additional artifact can break something.

It doesn’t seem to be a problem when I add a second artifact myself.

Link to the same question on Stackoverflow: https://stackoverflow.com/q/57272576/3052438

There is a bounty on this question on Stackoverflow, so if someone wants to get w whole lot of points, it’s a good opportunity. Just saying.