Hi. Continuing with my Gradle learning process, I have this situation:
For a Java Project, my main build output classes folder, as configured by default with Gradle is:
myProject/build/classes/main
Suppose now that I have a task which generates classes that I’m storing in a secondary classes folder, like so:
myProject/build/classes/generated
Two questions:
- How can I, specifically, tell Eclipse (via the Eclipse Plugin) that its class path should include this location, like so:
<classpathentry kind="lib" path="/home/code/my-project/build/classes/generated"/>
This instructs Eclipse to “Add a class folder” on its Java Build Path. I tried doing the same with the Gradle build file:
eclipse {
classpath {
file {
withXml {
def node = it.asNode()
node.appendNode('classpathentry', [kind: 'lib', path: project.ext.generatedClassesDir])
}
}
}
}
Note that ‘project.ext.generatedClassesDir’ is a ‘file()’ object.
Upon initial import into Eclipse of the project, the class folder was not added to the build path.
However, if I run the “eclipseClassPath” task once the project has been imported, the folder gets added but the Gradle dependencies declared in the project are added a second time to the build path as direct project dependencies (i.e. One set defined as “Gradle Dependencies” and again as a full list of direct jar dependencies).
So that’s one thing. Now:
- During my main build process (‘jar’ task for this project), how can I instruct the Java plugin to also copy the classes from this secondary generated classes folder into my resulting jar file? Is that possible? I mean, I could do a simple copy but I’m hoping there’s a declarative way to do this instead.
Thanks again for your time and help!