Gradle version of ant's 'Bootclasspath'


I need to place two jars “in front” of the standard java jars (aka <java_home>/lib/x.jar) in a legacy module. This works like this in ant: <javac

I’ve gotten this far in gradle:

options.bootClasspath = ‘source/lib/corbajunk1.jar;source/lib/corbajunk2.jar;??’

Am I going in the right direction? Should i use system properties? What’s best practice?

I would be nice to have it looking like this:

configurations {

corbaJunk }


Im sort of new to both gradle and groovy :slight_smile:

I think you want to look at modifying the JavaCompile options property.

The options property relates to CompileOptions which has the ability to setBootClasspath()

So it would look something like (example code):

configurations {
  dependencies {
  corbaJunk 'org.corba:corbajunk1:1.0'
  corbaJunk 'org.corba:corbajunk2:2.0'
  compileJava {
  options {
    bootClasspath = configurations.corbaJunk.asPath()

Thanks for the quick reply. My code ended up looking like:

… compileJava {

def env = System.getenv()

// println configurations.corbaJunk.asPath+’;’+env[‘JAVA_HOME’]+’/jre/lib/rt.jar’

options.bootClasspath = configurations.corbaJunk.asPath+’;’+env[‘JAVA_HOME’]+’/jre/lib/rt.jar’ }

Is there a more elegant way to make getting the rt.jar back on the bootclasspath or is it possible to “prepend” to the bootclasspath as:-Xbootclasspath/p: <my_special_lib>?


Now i want eclipse to understand that corbaJunk need to be “before” in the path. I relized that manually modifying the generated .classpath file (moving the xml elems for corbaJunk above the JRE) does the trick. I know this is doable and I guess that the magic should be applied sort of like:

eclipse {

classpath.file {

beforeMerged { classpath -> //here

} }


I think I asked the same question as the original of this thread

The problem I have with Karl-Johan’s solution (which is the basically same as the one I had) is that it assumes that the bootclasspath only comprises rt.jar and this may not always be the case.

A quick Google search brought up ‘-Xbootclasspath/p’:

You should be able to use this option via ‘options.compilerArgs’. Unless the Java compiler API doesn’t like it.


Why I had it in a configuration in the first place was that I was gunning for putting it first in the eclipse classpath as well. I sort of gave up on that since bootstrapping was needed to start the app out of eclipse. Anyway, not really high prio since our company is about to rid ourself from the horrors of corba…