Gradle in eclipse is not showing external dependencies sources and java docs in eclipse IDE

16.1k Views Asked by At

I am new to gradle. I converted one of my maven project to gradle. I installed eclipse gradle plugin. After that I configure my gradle like below

Eclipse Gradle configuration

Here is my build.gradle

apply plugin: 'application' // implicitly apply java and distribution plugin
apply plugin: 'eclipse'

sourceCompatibility = 1.8
targetCompatibility = sourceCompatibility

mainClassName = "com.softech.ls360.integration.BatchImport"

version = '1.0'

repositories {
    mavenCentral()
    mavenLocal()
}

ext {
    log4jGroupId = "org.apache.logging.log4j"
    springFrameworkGroupId = "org.springframework"
    springFrameworkVersion = "4.2.4.RELEASE"
    ....
}

dependencies {
     ['spring-context-support', 'spring-oxm', 'spring-test', 'spring-jms'].each {
        compile "$springFrameworkGroupId:$it:$springFrameworkVersion"
    }
    ...
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.11'
}

task copyJars(type: Copy) {
    ....
}

task copyConfigurationFiles(type: Copy) {
    ....
}

jar {
    ....
}

eclipse {
    classpath {
       downloadSources=true
       downloadJavadoc=true
    }
}

uploadArchives {
    repositories {
       flatDir {
           dirs 'repos'
       }
    }
}

I tried by right cliclking on project --> Gradle --> Refresh Dependencies. Also Refresh sources, refresh all. I saw in the console that eclipse downloaded the sources and jars

Gradle Downloaded Sources

Here is the javadocs screen shot

Gradle Javadocs Sources

If i expand the Gradle dependency and click one of the dependency jars, then it shows the code like

Gradle dependency expand tree

But from the eclipse editor when I click on one of the class then I got screen like this

Right click to see source code

No course code

No source is showning

Why ? Here is my project build path

Project Build path

In maven project it works perfectly fine. It open the source code. I can put breakpoints there. Although I can't modify the code, but at-least for debugging it works perfect.

How can I configure gradle for this situation? I tried by eclipseClean clean. Close the eclipse. Then open and importing the project. But result is same.

Am I missing something in build.gradle ?

Thanks

EDIT: __________________________

Here what I noticed.

Click to see JMS code

I get screen like this

Point to wrong jar

See It is pointing to Spring-context jar instead of spring-jms jar. But when I change it to location, by clicking on External File, where gradle downlaoded sources. It starts show sources

Selecting correct jar

Select correct jar

source starts showing

I don't know why it is behaving like this. May be I did something wrong while setup the project that's why it is behaving like this.

HHmm don't know hwy ?

Thanks

3

There are 3 best solutions below

0
On

For me the following steps solved this:

  1. Open "Gradle Tasks" view.
  2. Right click on ->ide->cleanEclipse
  3. Execute "Run Gradle Tasks" (takes a while to finish)
  4. After that in Package Explorer, right click on the project "Gradle-> Refresh Gradle Project".

Solving "Project and External Dependencies" issue

0
On

I am seeing the issue in Eclipse 2021-03 after running gradle init, then adding the gradle nature in Eclipse and finally running Gradle -> "Refresh Gradle Project". The "Project and External Depencies" library does not show up unless the rootProject.name in settings.gradle matches the Eclipse project name.

1
On

It happened to me also with Eclipse 2021-09. This helped me:

  1. close Eclipse
  2. run from command line "gradlew clean build"
  3. open Eclipse

Note: The .classpath file is not touched by the action. So I assume that it has nothing to with it.