如何在IntelliJ中附加gradle-api源代码

huangapple go评论99阅读模式
英文:

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?

如何在IntelliJ中附加gradle-api源代码

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 是不起作用的。

解决方案

  1. 设置 Wrapper.DistributionType.ALL
wrapper {
    jarFile = file(System.getProperty("user.dir") + '/gradle/wrapper/gradle-wrapper.jar')
    gradleVersion = '6.7.1'
    distributionType = Wrapper.DistributionType.ALL
}
  1. 我下载了Gradle,并使用它。在这里设置两个参数并刷新它。

如何在IntelliJ中附加gradle-api源代码

这是源代码,版本正确,并且名称中包含 allgradle-6.7.1-all):

如何在IntelliJ中附加gradle-api源代码

英文:

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

  1. set Wrapper.DistributionType.ALL
wrapper {
    jarFile = file(System.getProperty("user.dir") + '/gradle/wrapper/gradle-wrapper.jar')
    gradleVersion = '6.7.1'
    distributionType = Wrapper.DistributionType.ALL
}
  1. I download Gradle, and use it. Set two things here and refresh it.

如何在IntelliJ中附加gradle-api源代码

Here is the source code, the version is right and with all in the name (gradle-6.7.1-all):

如何在IntelliJ中附加gradle-api源代码

答案3

得分: 0

  1. 删除 gradle 文件夹
  2. 运行 "gradle wrapper"
  3. 检查文件 gradle/wrapper/gradle-wrapper.properties 中的后缀 "-all"
    示例:
    distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
英文:
  1. delete gradle dir
  2. run "gradle wrapper"
  3. check the suffix "-all" in the file gradle/wrapper/gradle-wrapper.properties
    sample:
    distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip

huangapple
  • 本文由 发表于 2020年7月29日 05:25:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63142990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定