Eclipse/Tomcat publishing unnecessary/problematic dependencies


(Justin Soden) #1

So first off, a little background.

I am working on converting an Eclipse Java Web Project to Gradle. We use the Vaadin framework and currently manage the project with Ant/Maven/Ivy. We have another project that contains common code that the web project depends on. In both projects our library files, JARs, are simply included in the source and committed to our VCS. With the switch to Gradle we will be using the preferred method of pulling our dependencies from a repository; mainly Maven Central.

I have completed creating the Gradle build scripts that correspond to our current Ant build scripts. I have one Gradle build script for each project, as well as one at the root for configuration injection along with the settings file. I am using the java and eclipse plugins for both projects and additionally the war and vaadin plugins for the web project.

Now to the problem. When I use Gradle to construct the WAR it works perfectly and the WEB-INF/lib directory contains only the JARs that I would expect, based on the dependency configuration. However, when I use Tomcat inside Eclipse to publish the project I end up with a bunch of additional JARs in the WEB-INF/lib directory. Most of the JARs are harmless and just unnecessary, which is why I have excluded them from the WAR, but there are a couple that are actually problematic because Tomcat already has them. In one case it just ignores the JAR and I get the usual message of > “[Tomcat] validateJarFile(***) - jar not loaded.”. In the other case I actually receive exceptions in the console, which is troubling even if the application appears to work correctly. I also noticed that all the dependencies associated with the testCompile configuration are also being published, which really doesn’t seem right.

The exact offending JARs are tomcat-jdbc and servlet-api-2.5. The tomcat-jdbc JAR is required for compiling our common code. The servlet-api-2.5 JAR is actually just a transitive dependency of vaadin-client-compiler. I have removed the dependency for the vaadin-client-compiler in our web project, because it doesn’t appear to be necessary, but it looks like it is still being pulled in by a configuration in the vaadin plugin for Gradle. However, in both cases I am using the providedCompile configuration of the war plugin to exclude them form the WAR.

So my question is, how do I keep Tomcat/Eclipse from publishing these JARs? How do Gradle and Tomcat/Eclipse communicate, or do they at all? From what I can gather it seems that Gradle and Tomcat/Eclipse only communicate indirectly via the .classpath, that the eclipse plugin for Gradle modifies. Also, I have tried the eclipse-wtp plugin for Gradle but I am not sure whether or not if it is necessary or if I can just simply use the eclipse plugin.

I should also add that I did install the Gradle Integration for Eclipse “plugin” via the Eclipse Marketplace. With that I used the Configure -> Convert to Gradle Project option that it adds as well as the Gradle -> Refresh Dependencies functionality that it provides. Other than that, I found it to be a little buggy so I’ve mostly been running Gradle via the command line.

Below is the output of running gradle -v on my machine:

------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------
  Build time:
 2013-12-17 09:28:15 UTC
Build number: none
Revision:
   36ced393628875ff15575fa03d16c1349ffe8bb6
  Groovy:
     1.8.6
Ant:
        Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:
        2.2.0
JVM:
        1.8.0_05 (Oracle Corporation 25.5-b02)
OS:
         Mac OS X 10.9.3 x86_64

Please let me know if additional clarification is required. I assume I must be doing something wrong or missing some configuration because surely my scenario is quite common. Many developers use Tomcat inside Eclipse to test web applications locally and with the popularity of Gradle I would be surprised if someone hasn’t run into this before. It would seem the main difference with our switch to Gradle, as far as Tomcat/Eclipse are concerned, is that our dependencies are now being loaded from a repository instead of being linked directly in the source.

Any help is greatly appreciated.


(Peter Niederwieser) #2

Are you using Eclipse WTP? If so, you should apply the ‘eclipse-wtp’ plugin to ‘allprojects {}’.


(Justin Soden) #3

We are not using Eclipse WTP. Which does answer my question about whether or not I would need that plugin.

Correction, WTP is installed, but I believe we are just using the server tools from it. Do I need to use the eclipse-wtp plugin if WTP is simply installed?


(Peter Niederwieser) #4

Not sure. Give it a try.


(Justin Soden) #5

I will have to get back to you in a bit; got some other work that is more pressing. I think I did try applying the eclipse-wtp plugin to both the web and common project and I don’t think it helped but I will try it again with allprojects.


(Justin Soden) #6

It appears that applying the eclipse-wtp plugin to allprojects did not resolve the issue. The unwanted JAR is still copied to WEB-INF/lib for the Tomcat instance in Eclipse.


(Justin Soden) #7

So using the eclipse-wtp plugin does not appear to resolve the issue. In particular, the tomcat-jdbc JAR is still being copied to the WEB-INF/lib directory.