Why does assemble run my task when it is not attached to the 'archives' or 'default' configurations?

Given a build.gradle and Gradle 4.10.1 below

plugins {

final myTask = tasks.create("myTask") {
  doFirst {

configurations.create("someConfig") {
  outgoing.artifact(file("someFile.txt")) {

Running ./gradlew assemble --dry-run outputs:

:assemble SKIPPED

Looking at https://docs.gradle.org/current/userguide/base_plugin.html

assemblelifecycle task

Plugins and build authors should attach tasks that produce distributions and other consumable artifacts to this lifecycle task.



A standard configuration for the production artifacts of a project. This results in an uploadArchives task for publishing artifacts attached to the archives configuration.

Nowhere in my build script am I attaching anything to the archives configuration or assemble task, so why is myTask going to be executed?

My example is contrived, but I am seeing this in an internal project where we have several configurations that contain the outputs for polyglot projects that are depended on from a multi-project perspective like project(":some:path", "someConfig") and we want to separate the built into stages. In our actual project, we have the java plugin applied and this still happens.

Ok, well I least I think I found the code path.

The logic in DefaultArtifactPublicationSet is confusing, and the execution behavior more so. Why would adding artifacts to my own configuration also be reflected in the archives configuration, and then be built during assemble? There is no configuration.extendsFrom relationship - there are some hard to discover rules baked into the base plugin that make this interaction awkward and surprising.

Even stranger is if you have a custom jar task (like shadow) and add it to that other configuration, it does not get added and built by assemble. There is some special logic that only adds the first (?!?) JAR that gets added as an artifact - https://github.com/gradle/gradle/blob/v4.10.1/subprojects/plugins/src/main/java/org/gradle/api/internal/plugins/DefaultArtifactPublicationSet.java#L48-L50

I discovered https://github.com/gradle/gradle-native/issues/730 and commented there. It sounds like this going to be eventually replaced based on the comment at https://github.com/gradle/gradle-native/issues/730#issuecomment-423362316

I filed https://github.com/gradle/gradle/issues/6875 as a follow-up to that comment