I'm using Gradle with the Eclipse plugin to generate project files for my project, but I can't get it to put the correct JRE version in .classpath
. I can add a JRE container, but I can't figure out how to remove the default one - and since this project is shared between developers, who might have varying defaults set in Eclipse, I want to control this manually.
The way I think this should work, is like so:
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.6
Since targetCompatibility
is the same as sourceCompatibility
, I expect this setup to go to the Eclipse settings, find a JRE that matches the source version (and yes, there is one on my machine - both a JRE installation and a separate JDK installation) and go with it.
Instead, however, it picks the default, which on my machine happens to be Java 7.
I tried adding some stuff to the Eclipse configuration:
eclipse {
jdt {
sourceCompatibility = 1.6 // tried with and without this
}
classpath {
// tried various ways to remove the old entry, among them:
file.beforeMerged { p -> p.entries.clear() }
// and then I add the "correct" one
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45'
}
}
Doing things like this I end up with two JRE containers in .classpath
:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45" exported="true"/>
</classpath>
How do I tell gradle that I only want a JRE 1.6 container, and not the default one too?
Some constraints on what I'm after:
- The default setting in Eclipse should be irrelevant
- Preferrably, I want the script to look up the container - in the above script, the string defining the container to add is user-dependent. I would like it much better to look among "installed JREs" for a version matching that of
sourceConfiguration
- I'm OK with throwing an error if no such JRE is installed in Eclipse.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…