WAR + EclipseWtpPlugin Shadows Source Attachments with Web App Libraries Container

When using the ‘war’ plugin and the ‘eclipse-wtp’ plugin, Gradle will automatically attach the Web App Libraries container (‘org.eclipse.jst.j2ee.internal.web.container’) as of 1.0-rc-1 per GRADLE-1974.

The dependencies in the ‘.classpath’ do list their source attachments as I would expect. However, because the web libraries container is turned on it shadows the .classpath entries and prevents the source from being attached. Per the discussion in GRADLE-2123, the container stores it’s source attachment in the Eclipse workspace, which isn’t (and shouldn’t be) reachable from Gradle.

There is a simple workaround:

eclipse.classpath.containers.removeAll(EclipseWtpPlugin.WEB_LIBS_CONTAINER)

However, I don’t buy the reason for GRADLE-1974 adding that container as a default. The only benefit it provides is support for JARs manually included in WEB-INF/lib, which seems like a bad practice in the first place. Trading that source attachments for that benefit feels like a raw deal.

Andrew, thanks for this work-around. It looks like it resolves a long-standing issue for us.

Hey Andrew!

Thanks for reporting this issue. If I understand the problem correctly the sources are not correctly configured by default when eclipse-wtp is applied? E.g. it’s not possible to navigate the source code conveniently from the IDE unless web container is removed?

The sources are correctly configured, if you look at the .classpath file. However, the presence of the Web App Libraries container seems to take precendence over any of the JARs that are both destined for WEB-INF/lib and part of the .classpath. In these cases, they only show up under the container, which doesn’t respect the source attachments from the .classpath.

I have found this similar issue on stackoverflow: http://stackoverflow.com/questions/12836089/why-is-eclipse-not-attaching-3rd-party-libs-source-files-to-a-wtp-faceted-gradle Solution given there is quite simple: “put the ‘Web App Libraries’ entry at the bottom of your classpath file”.

There is also a build file enhancement provided to to it automatically

I’m still getting this issue with Gradle 1.12 and Eclipse Kepler.

I think the issue here is simply that Gradle adds the Web App Libraries container before the other JARs in .classpath. As I’ve played around with Eclipse, it seems to always add the Web App Libraries container last.