我在一家大公司工作,该公司有严格的政策,禁止未经过滤地使用外部库。我们必须从受祝福的公司存储库中提取所有内容,而不是从裸露的互联网中提取所有内容,包括 gradle.org。
使用 gradle 的原始应用插件语法,结合 buildscript block ,我可以将(祝福的)插件添加到我们的 repo 并在构建中使用它们。换句话说:
buildscript {
repositories {
maven { url "https://privaterepo.myemployer.com" }
}
dependencies {
// various dependencies
classpath "org.something:some-plugin:1.0"
...
}
apply plugin: "someplugin"
相反,我希望能够使用新的插件 DSL,即
plugins {
id 'org.something.some-plugin' version '1.0'
}
(我意识到需要在某个地方定义私有(private) repo url)
新的插件语法总是转到 gradle.org 并且似乎没有任何方法可以提供备用下载 url。有人知道方法吗?
我仔细检查了文档和 Internet,但找不到答案。如果答案完全显而易见,我们深表歉意。
非常感谢!
最佳答案
Gradle 3.5 有一个新的 (incubating) 功能,允许更好地控制插件依赖解析,using the pluginManagement
DSL :
Plugin resolution rules allow you to modify plugin requests made in
plugins {}
blocks, e.g. changing the requested version or explicitly specifying the implementation artifact coordinates.To add resolution rules, use the
resolutionStrategy {}
inside thepluginManagement {}
block:Example 27.6. Plugin resolution strategy.
settings.gradle pluginManagement { resolutionStrategy { eachPlugin { if (requested.id.namespace == 'org.gradle.sample') { useModule('org.gradle.sample:sample-plugins:1.0.0') } } } repositories { maven { url 'maven-repo' } gradlePluginPortal() ivy { url 'ivy-repo' } } }
This tells Gradle to use the specified plugin implementation artifact instead of using its built-in default mapping from plugin ID to Maven/Ivy coordinates.
The
pluginManagement {}
block may only appear in the settings.gradle file, and must be the first block in the file. Custom Maven and Ivy plugin repositories must contain plugin marker artifacts in addition to the artifacts which actually implement the plugin.
pluginManagement
中的 repositories
block 与以前版本中的 pluginRepositories
block 的工作方式相同。
在 Gradle 3.5 之前,您必须 define the pluginRepositories
block在您的 settings.gradle 中,如 sytolk 的回答中所述:
The pluginRepositories {} block may only appear in the settings.gradle file, and must be the first block in the file.
pluginRepositories { maven { url 'maven-repo' } gradlePluginPortal() ivy { url 'ivy-repo' } }
https://stackoverflow.com/questions/37285413/