1

I'm using the Gradle eclipse plugin and I'm trying to connect two project. One of these project is a library and gets never exported since I just link to the library source in real projects. The other project should have a virtual link to the library source and add the linked directory as source directory to classpath. How can I do this with build.gradle? The has a feature for adding required projects (Project Properties -> Java Build Path -> Projects) or virtual source folders (Project Properties -> Java Build Path -> Source -> Link Source...), but it doesn't seem possible to use these features with Gradle java, Gradle eclipse or Gradle eclipse-wtp plugins.

admdrew
  • 3,790
  • 4
  • 27
  • 39
Aich
  • 962
  • 2
  • 9
  • 19
  • Try `linkedResource` as shown in the [Build Language Reference](http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.eclipse.model.EclipseProject.html). – Peter Niederwieser May 07 '14 at 17:34
  • Yep, this is what I am currently using. That just links to a folder and does not inteprret the subfolder hierarchy as packages. It also doesn't search for errors in code. Oh, and the most important thing: It won't compile that virtual source folder. – Aich May 07 '14 at 20:18
  • If you are already using `linkedResource`, you should describe this in detail as part of your question. If `linkedResource` doesn't cut it, you may have to use the `eclipse` plugin's hooks to generate the required XML directly. For general information on these hooks, see the [Gradle User Guide](http://gradle.org/docs/current/userguide/userguide_single.html) and the samples in the full Gradle distribution. – Peter Niederwieser May 07 '14 at 20:23

1 Answers1

0

I know this is an old thread, but having it answered in greater detail may help someone in the future who like me would otherwise spend a good bit of (wasted?) time googling to arrive at the answer.

What I'm guessing Peter was alluding to in his last comment was this:

If you have declared the linkedResource, you can then add it to the .classpath file using the classpath declaration as shown in the following:

eclipse {
    project {
        linkedResource name: 'java', type: '2', location: '[path-to-folder-to-be-linked]/src/main/java'
        linkedResource name: 'java-resources', type: '2', location: '[path-to-folder-to-be-linked]/src/main/resources'
        linkedResource name: 'test', type: '2', location: '[path-to-folder-to-be-linked]/src/test/java'
        linkedResource name: 'test-resources', type: '2', location: '[path-to-folder-to-be-linked]/src/test/resources'
    }
    classpath {
        file {
            withXml {
                def node = it.asNode()
                node.appendNode('classpathentry', [kind: 'src', path: 'java', exported: true])
                node.appendNode('classpathentry', [kind: 'src', path: 'java-resources', exported: true])
                node.appendNode('classpathentry', [kind: 'src', path: 'test', exported: true])
                node.appendNode('classpathentry', [kind: 'src', path: 'test-resources', exported: true])
            }
        }
    }
}

In my case, I am linking to files on another machine on my network, so the [path-to-folder-to-be-linked] is something like "/Volumes/pf/Documents/workspace/...".

Once you have the above in build.gradle and if you are using the Gradle tooling in STS/Eclipse, open the Gradle Tasks view, select the project, refresh task list, and finally run "eclipseClasspath".

Attribution: I cobbled the above together from this post (Eclipse plugin: add new element to a classpathentry).

pfurbacher
  • 1,789
  • 3
  • 15
  • 23