0

I have 2 projects, project A and B, how put/link project A inside project B classpath?

Every time I need to make it manually, click on Configure Classpath on project B, click on Projects tabsheet, add the project, after that, click on Order and Export and put the project on top of the classpath, but of course, if I clean the project B everything I made is lose, how to tell the Gradle to make it for me?

See the image bellow, I wanna the Gradle do it for me, how to?

enter image description here

Rodrigo Rodrigues
  • 649
  • 2
  • 12
  • 25
  • From your description it is not clear if your projects are part of one Gradle build / separate Gradle projects / not a Gradle projects at all. Also do you use `eclipse` plugin in Gradle build scripts to generate Eclipse project? Or do you import Gradle project into Eclipse using Eclipse plugin from Pivotal (also part of Spring Tool Suite)? – Radim Dec 01 '14 at 15:46
  • I have the project ModCustomer(as you can see at the image), I need to add ManageCore and jcomponents projects (see the image) to the ModCustomer classPath, I did it manually, I'd like to do it from Gradle. All the projects are gradle project and they are separated. I've created the gradle project from Eclipse Tool Suite – Rodrigo Rodrigues Dec 01 '14 at 18:35
  • The correct way to make dependencies between separate projects is to publish a jar artefact built from one project and declare it as a dependency in the other project. The correct way to do it if your projects are part of one multi-project build is to declare a project dependency in your build.gradle. The 'withXml' hook below may work but it isn't a nice/good way to deal with dependencies. – Kris Dec 02 '14 at 17:16

2 Answers2

1

You can customize how .classpath is generated in your build script using eclipse.classpath.withXml hook described in http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.eclipse.model.EclipseClasspath.html

Gradle does not know about projects in your Eclipse workspace so your customization probably should be optional. STS plugin for Eclipse can do this but ironically it does it for Maven projects only (i.e. if a dependency of your Gradle project is an output of a Maven project it replaces library JAR on classpath with a project reference).

Radim
  • 4,721
  • 1
  • 22
  • 25
  • Hi, I'm sorry, but I still dont understand how to tell to the Gradle to add the one Eclipse Project in Gradle project. What can I type in "classpath" configuration in EclipsePlugin of Gradle to make this settings for me? – Rodrigo Rodrigues Dec 09 '14 at 10:18
  • Well, after I do manually the settings, cheking the .classpath file, I saw the lines the question is, how make the gradle do it for me from build.gradle file? – Rodrigo Rodrigues Dec 09 '14 at 10:38
1

Put the following in your build.gradle to add the "ManageCore" and "jcomponents" projects to your .classpath file in Eclipse:

eclipse.classpath.file.withXml { xml ->
    def node = xml.asNode()
    node.appendNode('classpathentry', [ combineaccessrules: false, exported: true, kind: 'src', path: '/ManageCore' ])
    node.appendNode('classpathentry', [ combineaccessrules: false, exported: true, kind: 'src', path: '/jcomponents' ])
}

Hope this helps.

Andreas Schmid
  • 1,195
  • 8
  • 13