Intellij: Java: download sources for external dependencies

Created on 18 Jan 2017  Â·  8Comments  Â·  Source: bazelbuild/intellij

Let's say I have used maven_jar() in my WORKSPACE to make apache httpclient available to declare as a dependency, and that I am able to build my project without any problems with code using this external dependency.

When I in IntelliJ try to Go to → Implementation on a class from the dependency and click on "Download" in the bar at the top of the opened class file, I get an error Sources not found: Sources for 'httpclient-4.5.2-ijar.jar' not found.

I suspect this is due to the ijar trick bazel is doing?https://github.com/bazelbuild/bazel/tree/master/third_party/ijar

The functionality to easy download sources for external dependencies is a great feature, and I miss it very much.

Should this be working? Am I missing something?

Bazel version: 0.4.3

Most helpful comment

I'd suggest having this issue open until it has been resolved without requiring overriding maven_jar.

All 8 comments

This is basically the same issue as #31. The bazel plugin only sees the output from bazel, which doesn't include the sources. Until that's supported more naturally by bazel, you'll need a workaround.

The gerrit project has an example of this, which should work in conjunction with the bazel IntelliJ plugin:
https://gerrit.googlesource.com/gerrit/+/master/tools/bzl/maven_jar.bzl

Thanks!

I'm not sure I understand. Are you saying that if I use this skylark rule instead of the built-in maven_jar WORKSPACE rule, the IntelliJ plugin _will_ attach source jars automatically?

That's right -- the skylark extension will create a java_import target with the relevant srcjar attribute value filled in. That Skylark extension just overrides the behaviour of maven_jar, so you'll need to load it in the WORKSPACE file (see the gerrit project's WORKSPACE file as an example). Then just leave all your maven_jar targets as they were.

You can test it by loading that gerrit project in IntelliJ (you'll need Bazel 0.4.4 or later, and IJwB 2017.01.09 or later).

I tried using a modified version of gerrit's maven_jar replacement, and found that IntelliJ complained that the jar's bytecode didn't match what was being referenced by the source. It seems like there's some confusion going on between the ijar and the source jar?

Not "confusion" exactly, but Bazel does configure IntelliJ to use ijars by default. I believe that's on purpose?

I'd suggest having this issue open until it has been resolved without requiring overriding maven_jar.

This change should be made in Bazel -- the open issue is https://github.com/bazelbuild/bazel/issues/308

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lifeiteng picture lifeiteng  Â·  4Comments

davido picture davido  Â·  6Comments

Maririri picture Maririri  Â·  7Comments

ghost picture ghost  Â·  6Comments

brownry1986 picture brownry1986  Â·  8Comments