eclipsegradlegradle-eclipse

How can I use Gradle dependency managemenent with an Eclipse WTP project without errors?


I am new to Gradle. I've setup my project as a Gradle Project with the Gradle plugin, so that the project configuration is rebuilt based on the gradle build script. I'm trying to setup my app as a dynamic web project (using the eclipse-wtp Gradle plugin), and do so that, I need my project to have access to the Tomcat Server Runtime library.

Apparently the way to do that in Gradle is to set it up as a "provided dependency," which should only be used for compile but not deployed. However, that's not working for me for my IDE Tomcat deploys. It appears Gradle is configuring two sets of dependencies: Web App Libraries, which respects the provided dependency setting, and Grade Dependencies, which does not. Both are getting included in the web app deployment assembly, which means the "provided" Tomcat jars are getting deployed and preventing Tomcat from starting.

How can I configure Gradle to prevent the Gradle Dependencies from being automatically being included in the Eclipse deployment assembly screen? I cannot manually remove it, since it will just get refreshed the next time Gradle runs.


I've already tried Remove Gradle Dependency Management (Right click project -> Gradle -> Remove Gradle Dependency Management), but that doesn't work. It solve the Tomcat problem, but then my testing dependencies are no longer on the build path, which causes my unit tests to have errors.

The above actually works if you then also manually Gradle -> Refresh All. That will cause the Gradle Eclipse plugin to regenerate a the configuration files, and the dependencies that are not part of Web App Libraries will be included in Referenced Libraries.

Gradle -> Remove Dependency Management will just remove the Grade Dependencies library, and is not sufficient in and of itself.


I am using:

This is the library which is causing problems, it includes the "provided" Tomcat jars:

Gradle Dependencies

This is my build.gradle file:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
webAppDirName = 'WebContent'

// <snip>

dependencies {
    providedCompile('org.apache.tomcat:tomcat-catalina:7.0.34')

    // <snip>
}

// snip

Solution

  • The recommended way to work with WTP projects is to import them with 'dependency management' disabled. This is because Gradle's tooling API, which is used to populate the 'Gradle Dependencies' container, doesn't support WTP projects.

    If you already have the project imported you can disable dependency management as follows:

    Right-click on project and select "Gradle >> Disable Dependency Management".

    You will then likely see errors on the projects because of the missing dependencies.

    Right-click on project and select "Gradle >> Refresh All".

    This will execute the 'eclipse' task and generate the eclipse metadata (.classpath file etc) in much the same way that you would if you did this from the commandline.

    If this doesn't work for you, there is one other option. You can leave 'Dependency managent' enabled and there is a global exclusion filter that you can use to remove 'unwanted stuff' from the deployment assembly. This is really not a nice solution, but more of a workaround for exactly the problem that you are having.

    Go to "Windows >> Preferences >> Gradle >> WTP". You can edit the list of regexps there to remove your tomcat dependency from the deployment assembly.