gradle - 在构建脚本中加载其他插件之前使用 gradle 插件
问题描述
我有自己的 gradle 插件,其中包含一个包含其他插件版本的文件。目前,每当我创建一个新项目时,我都必须将它们复制过来,因为我无法使用插件中的版本。
无论如何要加载我的插件,应用它,然后再加载其他插件?目前,当我将插件模型命名为 时,我只能自己为项目执行此操作buildSrc
,因为它会自动将其添加到其他模块中。
我想要实现的示例:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "ca.allanwang:kau:$kau_version"
}
// Apply plugin before other dependencies so I can use it
apply plugin: "ca.allanwang.kau"
dependencies {
classpath kauPlugin.android
classpath kauPlugin.kotlin
classpath kauPlugin.androidMaven
classpath kauPlugin.playPublisher
classpath kauPlugin.dexCount
classpath kauPlugin.gitVersion
classpath kauPlugin.spotless
}
wrapper.setDistributionType(Wrapper.DistributionType.ALL)
}
以及当我将插件作为主项目中的模块时的样子:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://plugins.gradle.org/m2/" }
}
apply plugin: "ca.allanwang.kau"
dependencies {
classpath kauPlugin.android
classpath kauPlugin.kotlin
classpath kauPlugin.androidMaven
classpath kauPlugin.playPublisher
classpath kauPlugin.dexCount
classpath kauPlugin.gitVersion
classpath kauPlugin.spotless
}
wrapper.setDistributionType(Wrapper.DistributionType.ALL)
}
解决方案
您应该能够通过组合不同的东西来实现您想要的:
- 通过
Plugin<Settings>
利用对象是_settings.gradle(.kts)
Settings
ExtensionAware
- 使用在同一设置文件中定义您的插件类路径
pluginManagement
- 在您的项目中应用插件,而不指定版本 - 请参阅此示例以获取不通过以下方式定义版本的更简单版本
pluginManagement
示例:带有插件的https://github.com/ljacomet/setttings-plugin-propsbuildSrc
但它可以被发布并用作二进制插件而没有任何问题。
推荐阅读
- linear-programming - 寻找 BDD 对涉及 x,y 概念的问题的应用
- java - 新 Cell 语句中的 if 语句
- c++ - 如何随机创建不同类的对象?C++
- javascript - 在材料表中添加自定义添加按钮
- javascript - 带有反应模板的电子锻造应用程序的 index.html 中的“未捕获的 ReferenceError:未定义要求”
- python - 逻辑回归中浮点数据类型所需的输出
- wpf - WPF MVVM 组合框 SelectedItem 无法正常工作
- node.js - Gatsby 错误 ReferenceError:从 JSX 迁移到 Typescript 时未定义 React
- java - 不同路由器上的 Java Server Socket 连接
- python - 带有`plotly`的动画情节