gpt4 book ai didi

What's the difference between `plugins {}` and `pluginManagement.plugins {}` in `settings.gradle`(在`settings.gradle`中`plugins {}`和`pluginManagement.plugins {}`有什么区别)

转载 作者:bug小助手 更新时间:2023-10-28 10:02:52 29 4
gpt4 key购买 nike



Basically the title.

基本上就是标题。


I couldn't find a simple comparison anywhere, explaining the differences between these two:

我在任何地方都找不到一个简单的比较,来解释这两者之间的差异:


pluginManagement {
repositories {
gradlePluginPortal()
google()
}

plugins {
id "com.some.awesomeplugin" version "1.2.3"
id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
}
}

// And these:
plugins {
id "com.another.greatplugin" version "2.1.37"
id "com.android.application" version "7.3.0" apply false
}

I'm aware that there can be 3 types of plugins in Gradle:

我知道Gradle中可以有3种类型的插件:



  1. Project plugins, whose apply() callback is called when the individual build.gradle files are evaluated:


class BuildPhasePlugin : Plugin<Project>


  1. Settings plugins, whose apply() callback is called when the settings.gradle file is evaluated:


class SettingsPhasePlugin : Plugins<Settings>


  1. Initialization plugins, whose apply() is called when initialization script (init.gradle) is evaluated:


class InitPhasePlugin : Plugin<Gradle>

I suppose these 3 types of plugin are somehow related to the plugins {} block they can be applied in in settings.gradle?

我认为这三种类型的插件在某种程度上与它们可以在settings.gradle中应用的插件块有关。


更多回答
优秀答案推荐

pluginManagement { plugins { ... } } does not apply any plugin and does not add them to any classpaths, and thus apply false is a no-op and should imho actually trigger a syntax error.

PluginManagement{plugins{...}}不会应用任何插件,也不会将它们添加到任何类路径中,因此应用FALSE是无操作的,应该会实际触发语法错误。


This block just centrally defines the versions for plugins when they are used in other places without a version.
Nowadays I would not use this block at all anymore, but instead use a version catalog to centrally define the versions including plugin versions.

当插件在没有版本的其他地方使用时,这个块只是集中定义插件的版本。现在,我根本不会再使用这个代码块,而是使用一个版本目录来集中定义版本,包括插件版本。


The plugins { ... } block on top-level actually applies the specified settings plugins (or just adds them to the classpath when used with apply false.

顶层上的plugins{...}块实际应用指定的设置插件(或者在与Apply False一起使用时只是将它们添加到类路径中。


更多回答

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com