1

I use Eclipse Mars.2 (4.5.2) with Buildship 1.0.14. Gradle version is 2.12.

I import my gradle project into the Eclipse. No .project or .classpath files exist before import. All modules imported successfully. But almost every project with java code has missed dependencies and showing red "X".

If you open a java file with error, you can see that Eclipse can't resolve the import. But if you open imported class by name, it can find it in the other module's dependency.

Gradle -> Refresh project doesn't help.

The necessary dependencies declared in the root build.gradle in this way:

ext.library = [
    swagger: [
            [ group: "io.swagger", name: "swagger-annotations", version: "1.5.3" ],
            [ group: "io.swagger", name: "swagger-core", version: "1.5.3" ],
            [ group: "io.swagger", name: "swagger-jaxrs", version: "1.5.3" ]
    ]
]

and in the modules I declare it like this:

dependencies {
    providedCompile library.swagger
}

When you execute gradle build from command line or even from Eclipse, the build is successful.

The small project example to reproduce this problem can be found on github (thank to RaGe for participating in that).

Could you help me to resolve this issue with Eclipse?

Community
  • 1
  • 1
dds
  • 2,335
  • 1
  • 31
  • 45
  • What gradle version are you using? – RaGe Apr 14 '16 at 21:48
  • Are you using gradle war plugin? – RaGe Apr 14 '16 at 21:49
  • Gradle version is 2.12. Yes, war plugin is used. – dds Apr 14 '16 at 21:58
  • 1
    Unable to reproduce with eclipse mars 2 and buildship 1.0.14. [Here's the sample code I used](https://github.com/foragerr/SO-36633482-eclipse-with-buildship). On fresh import into eclipse, buildship downloads all swagger and transitive dependencies and [imports work fine](http://i.imgur.com/B1vJh0U.png). – RaGe Apr 15 '16 at 01:29
  • RaGe, I was able to modify your example to reproduce the problem. Forked to https://github.com/ddska/SO-36633482-eclipse-with-buildship – dds Apr 15 '16 at 15:22
  • I haven't tried it yet, but doesn't your change fail from gradle command-line as well? Now the configuration providedCompile is not in the compile classpath. – RaGe Apr 15 '16 at 15:33
  • Yes, you are right, sorry. Will continue to try to reproduce it. – dds Apr 15 '16 at 15:38

2 Answers2

2

Answering with reference to the code sample you provided here.

You're not using the war plugin, but instead declaring your own custom configuration called providedCompile. Gradle and by extension, buildship/eclipse don't know what providedCompile means. So the dependencies you listed in providedCompile are not being used as compile time dependencies.

It follows that your import statements become compile time errors - both in eclipse and from gradle commandline with gradle build

You can add providedCompile to the compile classpath by doing:

sourceSets.main.compileClasspath += [configurations.providedCompile]

If you also add the eclipse plugin to your project, you can modify eclipse compile class path with:

eclipse {
  classpath {
    plusConfigurations += [configurations.providedCompile]
  }
}
RaGe
  • 22,696
  • 11
  • 72
  • 104
0

Guys on the official bug tracker told me that with gradle 2.12 the compileOnly scope can be used now, which is also wired up to Eclipse by default.

dds
  • 2,335
  • 1
  • 31
  • 45