How to download maven dependencies into project local directory and set eclipse classpath?

I’d like to do the following:

  1. specify some maven dependencies
  2. when doing a gradle run, pull the dependencies
  3. copy those dependencies to project local dir (e.g. libs)
  4. config eclipse .project to use local jar in classpath
  5. if possible, all other gradle tasks (e.g. compile, test etc) use project local classpaths

Is this possible?

specify some maven dependencies
use a dependencies block in your build.gradle

when doing a gradle run, pull the dependencies
=> this will be done automatically, if you apply for instance the 'java plugin"

copy those dependencies to project local dir (e.g. libs)
=> you could create a custom task for that
task copyDeps(type: Copy) {
from (configurations.compile+configurations.testCompile) {
include “.jar"
include "
.so”, “*.dll”
into rootProject.rootDir.getAbsolutePath()+"/lib"
//rename can be applied on the files if you want to remove the version from the jar for instance

config eclipse .project to use local jar in classpath

you want to use the eclipse plugin
’apply plugin:eclipse’
This nice plugin will do that automatically for you (you don’t even need to copy the dependencies in a custom directory, the .classpath will directly reference the dependencies artifacts from the gradle cache directory)

if possible, all other gradle tasks (e.g. compile, test etc) use project local classpaths
Eclipse classpath is only use for Eclipse (compilation, Junit tests execution within eclipse, …)
Gradle tasks don’t need that. As long as you declare the needed dependencies in a dependencies {} block, Gradle will be OK :slight_smile:

A better question might be to ask why you would want to do this. If you make your Eclipse project a Gradle project, it can detect the normal Gradle dependencies, without having to copy the jars into your project, even with the limited functionality available in the SpringSource Gradle plugin.

And even without making it a gradle project, the Eclipse plug-in ( does exactly what you want

Thanks everyone for the detailed response.

Regarding “why do this?”, here’s the scenario which I want to do, but not sure if it’s a valid usage of Gradle:

  1. I’m creating a baseline of an eclipse selenium java project, which will have a few “developers” working on this project, and some “users” using this project.
  2. users of this project will download the packaged zip containing all the dependencies, import into their own eclipse, which has all the classppath set up so they can start writing selenium tests. Those users do not use gradle directly.
  3. developers of this project will run a gradle cmd to pull the dependencies. Those “developers” use the created gradle file, but they don’t know much about the details. It is OK for their eclipse project’s classpath to point to gradle cache, but they should be able to run a “gradle package” command to create the package for the users (which should remove gradle itself as a dependency).

As François suggested, it seems I am able to:

  • have gradle pull dependencies to a cache folder, which gradle compile / run can manage classpaths
  • have gradle config eclipse.project to use the dependencies in cache folder
  • have gradle copy dependencies into a project local path

In order for “developers” in usage (3) to build a packaged eclipse project for the “users” in usage (2), I’m hoping that gradle can config eclipse .project to use dependencies in project local path instead of gradle cache.

You can always customize the .classpath generated by the gradle eclipse plugin to point to whatever you like.
(with the ‘withXml’ method)

But I think it’s a shame to go with so much trouble, just because the users (2) must be ‘Gradle-Free’. With the gradle wrapper, if they can point to the gradle version you’re using, they can use Gradle under the hood, without much knowledge about it.

If they are clients or some sort of users with very limited privilege / network access, I understand that you want to package everything for them.

I want to concur with what has been said, but if you really need to go that route you could try the Ivypot plugin for Gradle - although not exactly designed for what you want, iI can probably do the job. All you then need to do is setup Eclipse to point to a local Ivy repo created by the plugin.