【发布时间】:2018-06-28 04:01:20
【问题描述】:
我正在尝试进行设置,以便我可以使用 Gradle Versions Plugin 而无需将其添加到我的所有 build.gradle 文件中。
基于this answer to a related question,我尝试创建一个文件~/.gradle/init.d/50-ben-manes-versions.gradle:
initscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
}
}
allprojects {
apply plugin: com.github.ben-manes.versions
}
如果我尝试在我的仓库中调用 ./gradlew dependencyUpdates,我会得到:
FAILURE: Build failed with an exception.
* Where:
Initialization script '~/.gradle/init.d/50-ben-manes-versions.gradle' line: 13
* What went wrong:
Could not get unknown property 'com' for root project 'project-name' of type org.gradle.api.Project.
该答案说不要在插件名称周围使用引号,但由于这不起作用,我尝试添加引号(即:apply plugin: 'com.github.ben-manes.versions')。我得到了:
FAILURE: Build failed with an exception.
* Where:
Initialization script '~/.gradle/init.d/50-ben-manes-versions.gradle' line: 13
* What went wrong:
Plugin with id 'com.github.ben-manes.versions' not found.
有没有办法从 initscript 应用 Gradle 版本插件?
顺便说一下,我使用的是 Gradle 4.3.1。
【问题讨论】:
-
第一件事是
com.github.ben-manes.versions没有被引号包围。当您应用这样的插件时,您是通过 id 应用它。 -
@mkobit 正如问题中所述,我尝试了带引号和不带引号。
-
对不起,完全是我的错,我躺在床上错过了。我明天看看这个。
-
@mkobit 没问题!我认为无引号版本看起来也很重要,但其他答案似乎暗示缺少引号很重要。无论如何,如果你明天能再看一眼,我将不胜感激。谢谢!
标签: gradle