Gradle: artifactoryPublish execute from within build.gradle does not publish the artifacts to the repository

execute() is not part of Gradle’s Task API and should never be called. You want to use task dependencies instead.

task publishAllApis {
    dependsOn( subprojects.findAll {
        it.name.endsWith("api")
    }.collect {
        it.tasks.named("artifactoryPublish")
    } )
}

Calling tasks.named may fail since the task must exist, meaning the subprojects must be configured first. To avoid this issue, you can add a call to evaluationDependsOnChildren() to the buildscript containing the publishAllApis task.