0

I am creating Eclipse project files as shown:

eclipse {
    project {
        natures 'org.eclipse.jdt.core.javanature'
        buildCommand 'org.eclipse.jdt.core.javabuilder'
    }
    classpath {
        downloadSources true
        downloadJavadoc true
    }
}

I have a multi-project gradle build where projects reference each other and 3rd party libs. For projectA, its dependencies are:

dependencies {
    compile project(':projectB')
    compile project(':projectC')

    compile "com.google.guava:guava:${VER_GUAVA}"
}

This works great, except that the generated projects don't reference each other. It builds just fine, but it means that if I refactor something in projectB, references in projectA aren't refactored with it. The fix is apparently to set the referencedProjects variable of the eclipse configuration, but I'd like for this to be automatically populated based on the dependencies. Something like:

eclipse {
    project {
        referencedProjects dependencies.grep(dep is project)
        ...

Anybody have any hints?

Ned Twigg
  • 2,159
  • 2
  • 22
  • 38
  • If I create a new Gradle project in Eclipse using "flat mulyiproject" template then there is product and my-lib projects created where product depends on my-lib via Gradle compile dependency. Yet when i rename CoolLib#niceMethod() to CoolLib#bestMethod() it completes the refactoring correctly I think. Wonder what are the differences between your setup and the setup from the template... – aboyko Jan 12 '15 at 15:23
  • Do you mean the template at 7.3.3 here: http://www.gradle.org/docs/current/userguide/tutorial_java_projects.html? – Ned Twigg Jan 12 '15 at 20:43

1 Answers1

0

This is how I ended up fixing it:

// add all project dependencies as referencedProjects
tasks.cleanEclipse.doLast {
    project.configurations.stream()
    .flatMap({config -> config.dependencies.stream()})      // get all deps
    .filter({dep -> dep instanceof ProjectDependency})      // that are Projects
    .forEach({dep -> eclipse.project.referencedProjects.add(dep.name)}) // and add to referencedProjects
}
// always create "fresh" projects
tasks.eclipse.dependsOn(cleanEclipse)

Probably ought to mention that I'm using the wuff plugin because I'm in an OSGI environment, and it does tricks on the dependencies. That might be the reason that I'm not getting this automatically, but the above snippet fixes it pretty easily.

Ned Twigg
  • 2,159
  • 2
  • 22
  • 38