Adding dependencies to .classpath file from a subdirectory

How to add dependencies (Jars) to existing .classpath file of eclipse project (from subdirectory)?

Hello everyone, I wanted to include Jars in my Eclipse project, but my gradle script is in a subdirectory. When I run gradle eclipse creates in the subdirectory a copy of all my projects and adds the dependencies in these .classpath files. I just wanted to know how to tell gradle that itself lies in a subdirectory. Thanks everyone!

I don’t quite understand your question/explanation. Can you explain in more detail? Do you use Gradle just for generating the Eclipse project?


I use this code to add all the dependencies needed to the classpath files:

eclipse {

classpath {

//adding extra configurations:

plusConfigurations += configurations.compile

//default settings for dependencies sources/javadoc download:

downloadSources = true

downloadJavadoc = false



But when I start my gradle script with “gradle eclipse” it creates new .classpath files with the correct dependencies but just one subdirectory too deep:

The folder de.prob.releng contains the script, and should contain the script only, but gradle eclipse makes copies of the actual projects in this subdirectory and creates there the .classpath files.

It actually nearly works, it would just be nice if it would do the exact same thing one folder above.

So my question would be: Can you tell gradle that the actual workspace is one folder above the script itself?

( e.g. EclipseWorkspace = “…/” )

Thank you very much for your help!

Not sure why you’d want to put ‘settings.gradle’ and ‘build.gradle’ (but not ‘gradlew’ and the ‘gradle’ directory) into a subdirectory, but you can freely reconfigure project directories in ‘settings.gradle’. For example:

  def elevateProjectDir(project) {
  project.projectDir = project.projectDir.parentFile
  for (child in project.children) elevateProjectDir(child)

For more information about the API, see Settings in the Gradle DSL reference.

Actually this might not work because ‘build.gradle’ will no longer be found. Unfortunately there doesn’t seem to be a clear-cut way to have the build file in a directory other than the project directory; only the build file’s name can be changed.

If you have just one ‘build.gradle’, you can try to elevate all but the root project’s project directory. Another attempt is to configure the ‘inputFile’ and ‘outputFile’ properties of all Eclipse-related tasks. Something like:


gradle.allprojects {
  def ideTasks = tasks.withType(org.gradle.plugins.ide.api.XmlGeneratorTask)
  configure(ideTasks) {
    inputFile = new File(inputFile.parentFile.parentFile,
    outputFile = inputFile

Question is if moving the build scripts isn’t the better solution.

Thank you very much! The build.gradle and settings.gradle are in the subdirectory for easier subversion checkout.

Sounds like you are fighting the problem that Eclipse can’t properly handle hierarchical project structures. If that’s the case, have a look at the STS Gradle plugin, which handles this just fine.

Thanks I’ll give it a try.