gradle:如何找到实现特定任务的插件?

e5nszbig  于 2023-06-30  发布在  其他
关注(0)|答案(3)|浏览(133)

我有一堆Gradle插件在我的构建中使用。这些插件中的许多反过来使用其他插件。我想找出实现特定任务的插件。有没有一个核心的gradle任务来找出这一点?谢谢

ubof19bj

ubof19bj1#

没有核心任务会告诉你哪个插件负责哪个任务。您可以通过运行以下命令查看所有可用的任务:
gradle tasks
然而,日志中有一些提示。如果使用--debug开关运行构建,您可以看到在解决插件依赖关系后注册的任务:

10:20:25.847 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Found artifact 'gradle-release.jar (net.researchgate:gradle-release:2.3.5)' in resolver cache: C:\g\caches\modules-2\files-2.1\net.researchgate\gradle-release\2.3.5\8045af5040f3efa88abbc5879fd51cf1634a2536\gradle-release-2.3.5.jar
10:20:26.041 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.release' (hidden = false)
10:20:26.076 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.createScmAdapter' (hidden = false)
10:20:26.086 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.initScmAdapter' (hidden = false)
10:20:26.086 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.checkCommitNeeded' (hidden = false)
10:20:26.087 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.checkUpdateNeeded' (hidden = false)
10:20:26.088 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.unSnapshotVersion' (hidden = false)
10:20:26.088 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.confirmReleaseVersion' (hidden = false)
10:20:26.089 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.checkSnapshotDependencies' (hidden = false)
10:20:26.091 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.runBuildTasks' (hidden = false)
10:20:26.093 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.preTagCommit' (hidden = false)
10:20:26.094 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.createReleaseTag' (hidden = false)
10:20:26.094 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.updateVersion' (hidden = false)
10:20:26.095 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.commitNewVersion' (hidden = false)
10:20:26.127 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.beforeReleaseBuild' (hidden = false)
10:20:26.128 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.afterReleaseBuild' (hidden = false)

这将告诉你这个插件(gradle release)依赖注册的任务。

7vux5j2d

7vux5j2d2#

您可以打印每个插件和每个任务的类名,希望包能给予您一个提示
例如:

task printStuff {
    doLast {
        plugins.all { Plugin plugin ->
            println "Plugin: ${plugin.class.name}"
        }
        tasks.all { Task task ->
            println "Task: ${task.class.name} (name=${task.name})"
        }
    }
}
w7t8yxp5

w7t8yxp53#

我在根文件夹build.gradle中临时添加了以下代码:
这是针对名为lint的任务。你可以适应任何其他任务。

allprojects { project ->
    beforeEvaluate {
        tasks.whenTaskAdded {
            if (it.name == "lint") {
                println("++++++++ Task added, project: $project, class: ${it.class.name}")
            }
        }
    }
}

然后我就跑:

$ ./gradlew -q tasks

并且它打印出关于lint任务的信息,它们定义了哪些项目以及哪个是实现类名。从类名中我通常可以知道哪个插件定义了这个任务。

相关问题