简体   繁体   中英

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?

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 {
    // ...
}

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

dependencies {
   //...
   runtimeOnly(gradleApi())
   

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.

在此处输入图像描述

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

在此处输入图像描述

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM