0

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
Kaypro II
  • 3,210
  • 8
  • 30
  • 41
  • I'm on Gradle v2.5. This must be something that is added by the Gradle IDE Plugin for Eclipse. If you generate the eclipse output from the command line, there should be no "Gradle Dependencies" reference. – cmcginty Nov 20 '15 at 21:04
  • 1
    Casey is right. 'Gradle Dependencies' is the classpath container which Gradle STS tooling creates when you use 'managed dependencies'. Actually, officially there is no support for WTP in any version of Gradle's tooling API so the integration with WTP in tooling is pretty poor. Your best bet is to import the project and disable dependency management. Gradle STS tooling will then work differently and just execute the 'eclipse' task to configure project instead of using the tooling API. This works much better for WTP projects. – Kris Nov 23 '15 at 17:10

1 Answers1

2

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.

Kris
  • 3,898
  • 1
  • 23
  • 32
  • Oh hmm... sorry not sure why I didn't see that earlier. At the end of your question you have a comment you already tried this. There is one other thing you can try but it is not as nice a solution. I'll add as a extra component to my answer. – Kris Nov 23 '15 at 17:23
  • BTW, if you are having problems with the 'dependency managment disabled' scenario it probably means some kind of bug in 'eclipse-wtp' plugin that should be reported against Gradle. – Kris Nov 23 '15 at 17:27
  • I'll try giving the "dependency management disabled" setting another go. When I tried it, I didn't give it much of a chance once I saw some errors. When gradle generates eclipse metadata, how is it supposed to handle testing dependencies (i.e. where should I expect them to show up in the IDE w/o the Gradle dependencies library)? – Kaypro II Nov 23 '15 at 21:02
  • "where should I expect them to show up in the IDE w/o the Gradle dependencies library" I would expect to see them in the generated .classpath file. But your comments suggest this is not the case. – Kris Nov 24 '15 at 00:51
  • Thanks! That worked. I had only gotten build errors after removing gradle dependency management because I did not follow it with a refresh all. All the non-web-app dependencies now show up as Referenced Libraries in the UI. – Kaypro II Nov 30 '15 at 17:31
  • @Kris - Is it still the case that gradle eclipse plugin doesn't support dependency management in WTP projects? – Gurwinder Singh Jan 24 '18 at 10:44
  • @gurv With the STS 'legacy' tooling, yes. They are not really maintained anymore and haven't changed much in a long time. Its probably not advisable to keep using them at the moment. You should look into using BuildShip instead. I don't know as much about its internals and capabilities so I won't make guesses about what it can or cannot do on the risk of spreading misinformation. – Kris Jan 25 '18 at 18:59