Gradle add eclipse project to classpah

1.4k views Asked by At

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

2

There are 2 answers

2
Radim On

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).

0
Andreas Schmid On

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.