我正在尝试理解Gradle中buildscript {}
块是如何工作的。
我知道当引用外部插件时,应该使用它内部的repositories {}
块:
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
}
}
apply plugin: 'com.jfrog.bintray'
但是我不明白当buildscript {}
块中没有repositories {}
块时,Gradle在哪里寻找依赖项。如果我将它从上面的示例中删除,我仍然能够构建我的项目而不会出现错误:
buildscript {
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
}
}
apply plugin: 'com.jfrog.bintray'
在这种情况下,Gradle不应该抛出错误吗?
下面是我的完整build.gradle
文件:
buildscript {
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
}
}
plugins {
id 'java'
}
apply plugin: 'com.jfrog.bintray'
group 'it.foo'
version '1.0-SNAPSHOT'
我在Gradle 7.1.1上运行这个Gradle文件,但在Gradle 6.1.1上也有相同的行为。
发布于 2021-07-07 22:53:30
它确实抛出了一个错误...
在Gradle 7.1中恰好使用上面的示例,您会得到
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'norepo'.
> Could not resolve all artifacts for configuration ':classpath'.
> Cannot resolve external dependency com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5 because no repositories are defined.
Required by:
project :
https://stackoverflow.com/questions/68287553
复制相似问题