英文:
How to attach gradle-api sources in IntelliJ
问题
I'm working on a custom Gradle plugin. For some reason IntelliJ is unable to find the sources of the gradle-api
artifact and only shows the decompiled .class file. I am already using the -all
distribution of the Gradle Wrapper (which includes some sources, but apparently not the ones I need right here). Clicking Download... results in an error:
Sources not found: Sources for 'gradle-api-6.5.1.jar' not found
How do I correctly attach/choose sources for gradle-api
in IntelliJ?
EDIT:
I have a minimal Gradle plugin with code like that (taken from the official samples):
id 'java-gradle-plugin'
}
repositories {
jcenter()
}
dependencies {
testImplementation 'junit:junit:4.13'
}
gradlePlugin {
// ...
}
英文:
I'm working on a custom Gradle plugin. For some reason IntelliJ is unable to find the sources of the gradle-api
artifact and only shows the decompiled .class file. I am already using the -all
distribution of the Gradle Wrapper (which includes some sources, but apparently not the ones I need right here). Clicking Download... results in an error:
Sources not found: Sources for 'gradle-api-6.5.1.jar' not found
How do I correctly attach/choose sources for gradle-api
in IntelliJ?
EDIT:
I have a minimal Gradle plugin with code like that (taken from the official samples):
plugins {
id 'java-gradle-plugin'
}
repositories {
jcenter()
}
dependencies {
testImplementation 'junit:junit:4.13'
}
gradlePlugin {
// ...
}
答案1
得分: 1
根据这份出色的手册,你应该将gradleApi()
添加为runtimeOnly
依赖项:
dependencies {
//...
runtimeOnly(gradleApi())
}
英文:
According to this excellent manual you should add gradleApi()
as a runtimeOnly
dependency:
dependencies {
//...
runtimeOnly(gradleApi())
答案2
得分: 0
Here is the translation of the provided content:
我猜,默认的Intellij配置 use gradle from gradle-wrapper.properties file
会使用 /gradle/wrapper/gradle-wrapper.jar
,但它不包含源代码。你需要像 gradle-wrapper-all.jar
这样的JAR文件。但我不知道如何让Gradle重新下载它。只设置 Wrapper.DistributionType.ALL
是不起作用的。
解决方案
- 设置
Wrapper.DistributionType.ALL
wrapper {
jarFile = file(System.getProperty("user.dir") + '/gradle/wrapper/gradle-wrapper.jar')
gradleVersion = '6.7.1'
distributionType = Wrapper.DistributionType.ALL
}
- 我下载了Gradle,并使用它。在这里设置两个参数并刷新它。
这是源代码,版本正确,并且名称中包含 all
(gradle-6.7.1-all
):
英文:
I guess that, the default Intellij config use gradle from gradle-wrapper.properties file
will use /gradle/wrapper/gradle-wrapper.jar
, but it doesn't contain source code. what you need is a jar like gradle-wrapper-all.jar
. But I don't know how to let Gradle redownload that. Just setting Wrapper.DistributionType.ALL
is not working.
Solution
- set
Wrapper.DistributionType.ALL
wrapper {
jarFile = file(System.getProperty("user.dir") + '/gradle/wrapper/gradle-wrapper.jar')
gradleVersion = '6.7.1'
distributionType = Wrapper.DistributionType.ALL
}
- I download Gradle, and use it. Set two things here and refresh it.
Here is the source code, the version is right and with all
in the name (gradle-6.7.1-all
):
答案3
得分: 0
- 删除 gradle 文件夹
- 运行 "gradle wrapper"
- 检查文件 gradle/wrapper/gradle-wrapper.properties 中的后缀 "-all"
示例:
distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
英文:
- delete gradle dir
- run "gradle wrapper"
- check the suffix "-all" in the file gradle/wrapper/gradle-wrapper.properties
sample:
distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论