Because my Java sources and targets must be JRE 1.6 compatible, I need to set options.bootClasspath
to a path that contains the 1.6 versions of rt.jar
and jce.jar
. It must build on both Windows and Unix (Linux/Solaris). What is the proper way to do this? I now use the following approach in my top-level build.gradle
, it works, but it seems far from elegant, especially the os-dependent separator :
or ;
:
import org.apache.tools.ant.taskdefs.condition.Os
subprojects {
apply plugin: 'java'
compileJava {
sourceCompatibility = 1.6
targetCompatibility = 1.6
def java6_home = System.getenv("JAVA_HOME_6")
def java6_lib = "C:/localdata/Program Files (x86)/Java/jdk1.6.0_45/jre/lib/"
if (java6_home != null) {
java6_lib = java6_home + "/jre/lib/"
}
def sep = ':'
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
sep = ';'
}
options.bootClasspath = java6_lib + "rt.jar" + sep + java6_lib + "jce.jar"
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…