gpt4 book ai didi

kotlin - 无法在Gradle项目中使用pluginManagement block 应用Kotlin JVM插件

转载 作者:行者123 更新时间:2023-12-03 05:20:09 25 4
gpt4 key购买 nike

我正在使用Gradle Kotlin Scripts建立一个简单的Kotlin程序。初始build.gradle.kts文件和settings.gradle.kts文件非常简单:build.gradle.kts文件:

plugins {
id("org.jetbrains.kotlin.jvm") version "1.4.10"
}

group = "edu.nju.alex.wang"
version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib"))
}
settings.gradle.kts文件:
rootProject.name = "Barabra"
我正在尝试使用 pluginManangement块来控制Kotlin JVM插件的版本。所以我将代码更改为此。 build.gradle.kts文件:
plugins {
id("org.jetbrains.kotlin.jvm")
}

group = "edu.nju.alex.wang"
version = "1.0-SNAPSHOT"


dependencies {
implementation(kotlin("stdlib"))
}
settings.gradle.kts文件:
pluginManagement {
repositories {
mavenCentral()
jcenter()
google()
}

plugins {
id("org.jetbrains.kotlin.jvm") version "1.4.10"
}
}

rootProject.name = "Barabra"
但是,当我尝试执行Gradle任务时,它报告了一个错误:
* Where:
Build file '/home/jue/Storage/Barbara/Barabra/build.gradle.kts' line: 1

* What went wrong:
Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.4.10'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.4.10')
Searched in the following repositories:
MavenRepo
BintrayJCenter
Google
我是在做错什么,还是行不通?

最佳答案

您的问题的说明可以在这里找到:https://docs.gradle.org/current/userguide/plugins.html#sec:custom_plugin_repositories

pluginManagement {
repositories {
maven(url = "../maven-repo")
gradlePluginPortal()
ivy(url = "../ivy-repo")
}
}

This tells Gradle to first look in the Maven repository at../maven-repo when resolving plugins and then to check the GradlePlugin Portal if the plugins are not found in the Maven repository. Ifyou don’t want the Gradle Plugin Portal to be searched, omit thegradlePluginPortal() line. Finally, the Ivy repository at ../ivy-repowill be checked


在您的情况下,您已在 repositories中添加了一些存储库(google,jcenter,mavenCentral),但未添加 gradlePluginPortal,这是从中解析Gradle插件的默认位置。
似乎 org.jetbrains.kotlin.jvm版本中的 1.4.10插件(当前?)在 Gradle Plugins repository之外的其他存储库中不可用。
因此,解决方法:从 repositories中删除整个 pluginManagement块(如果不需要从自己的特定存储库解析插件),或者在列表中添加 gradlePluginPortal()

关于kotlin - 无法在Gradle项目中使用pluginManagement block 应用Kotlin JVM插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63906672/

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