将依赖项添加到 gradle 组任务

Add depencency to group of gradle tasks

我有一个包含大量发布任务的项目:

Publishing tasks
----------------
generatePomFileForMavenJavaPublication - Generates the Maven POM file for publication 'mavenJava'.
generatePomFileForMavenPublication - Generates the Maven POM file for publication 'maven'.
publish - Publishes all publications produced by this project.
publishMavenJavaPublicationToMavenLocal - Publishes Maven publication 'mavenJava' to the local Maven repository.
publishMavenJavaPublicationToMavenRepository - Publishes Maven publication 'mavenJava' to Maven repository 'maven'.
publishMavenPublicationToMavenLocal - Publishes Maven publication 'maven' to the local Maven repository.
publishMavenPublicationToMavenRepository - Publishes Maven publication 'maven' to Maven repository 'maven'.
publishToMavenLocal - Publishes all Maven publications produced by this project to the local Maven cache.

现在我希望所有这些任务都依赖于 build,以确保在发布任何内容之前进行测试和检查 运行(默认情况下,发布任务依赖于 assemble ).

当然有以下作品:

publish.dependsOn(build)
publishToMavenLocal.dependsOn(build)

但是维护起来很麻烦,而且对于像publishMavenPublicationToMavenRepository这样的任何生成的任务都不起作用。 有没有办法为所有发布任务添加依赖项? 当然我试过了 publishing.dependsOn(build) 但它只是说:

Could not find method dependsOn() for arguments [task ':build'] on org.gradle.api.publish.internal.DefaultPublishingExtension_Decorated@5b5f8cd6.

无法定义 group 依赖项,但是您可以尝试:

tasks.findAll { it.name.startsWith('publish') }*.dependsOn(DA_TASK)