When using JavaExec to run some class, Gradle runtime is found in the classpath


(Nicolas Berthet) #1

Hi,

I’m trying to run some simple task that depends on the code being built, just specifying the classpath and main class, as below:

task customTask(type: JavaExec) {
  classpath sourceSets.main.output + configurations.runtime
  main 'fqcn'
}

My classpath contains a library that relies on ASM 4.1, while gradle relies on ASM 5, thus it prevents my class from running properly when ran through JavaExec, it works just fine in eclipse or command line.

Note I’ve no dependency to gradle or gradleApi in any way, when printing the dependency tree, it looks just like what I expect.

Is there any way to exclude Gradle’s runtime from being in the classpath ? Did I miss some option ?

Thanks,

nicolas


(Nicolas Berthet) #2

Found a workaround, but it’s not so nice…

def all = files(sourceSets.main.output.classesDir) + files(sourceSets.main.runtimeClasspath)

all = all.filter { !it.path.contains("/gradle-2.0-bin/") }

classpath all


(Peter Niederwieser) #3

There is likely something in your build or init script(s) that causes Gradle Jars to end up on that class path. Gradle won’t do this on its own.


(Nicolas Berthet) #4

Thanks for the quick reply. I didn’t have much time to play with my scripts to find out where the problem comes from, but you’re right.

I’ve been setting up a similar project from scratch, and I didn’t have gradle api in my classpath.

My project has multiple sub-projects, one of them is a gradle plugin that depends on all other projects, maybe I had a cross project dependency I didn’t see.

Will update whether I find where it came from…