2

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

Basit
  • 8,426
  • 46
  • 116
  • 196
  • I just tried it and it works for me (both in the 'Gradle Dependencies' directly and via 'Right Click' from editor, I get source code. It is odd that it should work for one and not the other. Maybe you have multiple projects in the workspace that have same/similar jars on the classpath and only some of those projects have source-code attachement for the jars? – Kris Feb 10 '16 at 16:45
  • Hhmm yes I have other projects also. But one thing that I noticed. When I run `task eclipse`, my `.classpath` contain entries for the sorces and javadocs. But when I do `Gradle --> Refresh Dependencies` or `Refresh All`, my `.classpath` file remove all the entries. Also when it says `Change Attached Source`. And I click on it, then it show me wrong path. I mean to say let say I click on spring context code. No source code but in the editor there is option `Change Attach Source`. When I click on it, it contains path of some other jars , say `activeMQ`. When I correct the path. Source available. – Basit Feb 11 '16 at 07:23
  • Is your project having 'dependency management' enabled? I thought so because you have 'Gradle Dependencies' in your screenshot. On the other hand you talk about having dependencies listed in .classpath file as well. This is conflicting. The container provides the dependencies implicitly so they shouldn't be listed in the .classpath explicitly. Maybe you somehow have gotten in a situation where you have both and that's where the confusion is coming from (jars twice on project's classpath one with and one without source attachement)... – Kris Feb 11 '16 at 19:56
  • If you want the dependencies listed explicitly in .classpath then select 'Disable Dependency Management' and remove the "Gradle Dependencies" container. If you want the dependencies in the container instead then it is expected that they should 'disapear' from your .classpath (so don't try to add them back!). – Kris Feb 11 '16 at 19:58
  • Yes I have dependency management available. And I got your point. I didn't know about that `Disable Dependency Management`. But I have `Dependency Management Enable`. I think may be `Gradle` is not so much stable as `Maven` right now. I accept that I have very limited knowledge about `Gradle`. But I remember, I just installed Maven plugin in `Eclipse Kepler` and everything strated working. But this is not the case with `Gradle`. Now I am using `Eclipse Mars`, and I am having unusual issue with `Gradle`. May be because of `mavenLocal()` I am having issues. – Basit Feb 17 '16 at 08:13
  • I tried everything. I uninstalled `Gradle plugin`, uninstall `Gradle Enide Plugin`. Again installed it. Then finally I removed both and install `Gradle Integration plugin`. But results are same. No `source code`. I have `spring dependencies` in my project. With `Gradle` I am getting `Spring mismatch version errors. NoSuchMethod errors`. While same dependencies in `Maven` are working fine. I put `failOnVersionConflict`. I force gradle to use spring latest version. But I don't know why on runtime I am getting spring mismatch version issues with Gradle. – Basit Feb 17 '16 at 08:18
  • Not sure what else to suggest. Maybe you can zip up the contents of the project, or put it somewhere public like github, and put a link to it in your question. I can take a look and see if I can reproduce the problem. As it doesn't happen for me, I don't know what is causing this problem for you. – Kris Feb 17 '16 at 16:49

3 Answers3

3

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

ouflak
  • 2,458
  • 10
  • 44
  • 49
0

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.

Pavel Merta
  • 69
  • 2
  • 2
0

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.

Asencion
  • 309
  • 2
  • 11