I have a project with several subprojects, each of which sets sourceCompatibility
and targetCompatibility
. I would like Eclipse to respect these version numbers when I import the project, e.g., if I have sourceCompatibility = 1.6
, the project should use the JavaSE-1.6 execution environment as its JRE.
To accomplish this, I used to use the following code snippet:
afterEvaluate {
// Make Eclipse use the JRE matching version used by project, not the
// workspace default. Based on: http://stackoverflow.com/a/22866932
if (plugins.hasPlugin('eclipse')) {
if (project.sourceCompatibility != null) {
def target = project.sourceCompatibility.toString()
def containerPrefix = "org.eclipse.jdt.launching.JRE_CONTAINER"
def containerSuffix
if (target =~ /1.[4-5]/) {
containerSuffix = "/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE"
}
else if (target =~ /1.[6-9]/) {
containerSuffix = "/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE"
}
if (containerSuffix != null) {
def containerName = "${containerPrefix}${containerSuffix}-${target}"
project.eclipse.classpath {
containers.removeAll { it.startsWith containerPrefix }
containers.add containerName
}
}
}
}
}
The idea being to replace the default JRE container in the classpath with one of my own design. This works when I use the eclipseClasspath
task to generate the .classpath file, but not when Buildship generates its own .classpath file.
I read in a different thread that there is no plan to have Buildship merge in entries from the classpath generated by the eclipse plugin. Is there a way to set the JRE container, or will there ever be?
TL;DR: Is there a way to set the JRE container in a Buildship project from the gradle build script?