How to attach gradle-api sources in IntelliJ
Asked Answered
J

3

7

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

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 {
    // ...
}
Jameyjami answered 28/7, 2020 at 21:25 Comment(6)
How do you define the dependency in your project? The sources are available at repo.gradle.org/gradle/libs-releases-local/org/gradle/…. Did you add this repository in build.gradle?Anastigmat
Thanks @Anastigmat - That brought me a little closer. First I had to downgrade to Gradle 6.1.1 (somehow that's the last published version with the link you posted). Then it was possible to manually attach the download sources jar file. Automatic download still does not work, even after adding a custom repository to the build script.Jameyjami
How do you declare this dependency in build script? Do you have gradle composite build? Do you use Groovy DSL?Triturable
Looks like IDEA-221322, IDEA-197970.Triturable
Thanks @Triturable - It does indeed look like it's related to those tickets.Jameyjami
@Anastigmat - Do you happen to know if/where Gradle releases after 6.1.1 are published? repo.gradle.org, as well as mvnrepository, etc appear to only contain versions <= 6.1.1Jameyjami
P
2

According to this excellent manual you should add gradleApi() as a runtimeOnly dependency:

dependencies {
   //...
   runtimeOnly(gradleApi())
   
Picrotoxin answered 3/2, 2021 at 13:1 Comment(0)
M
0

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.

enter image description here

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

enter image description here

Madelainemadeleine answered 12/4, 2021 at 4:31 Comment(0)
K
0
  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
Kantianism answered 21/7, 2022 at 11:43 Comment(1)
Welcome to SO! Please a little textual explanation about how and why your approach works and what makes it different from the other answers given. You may also have a look at our "How to write a good answer" entry.Ovariotomy

© 2022 - 2024 — McMap. All rights reserved.