Ice
Ice

Reputation: 355

How do i print out the JAVA classpath in gradle?

I am currently using gradle integration with ecplise. Is there a way to print out the classpath of a javaexec task?

Upvotes: 20

Views: 29319

Answers (6)

codeape
codeape

Reputation: 100756

I add this task to all my gradle projects (build.gradle.kts syntax below):

tasks.register("saveClassPathToFile") {
    doFirst {
        File("classpath.txt").writeText(sourceSets["main"].runtimeClasspath.asPath)
    }
}

Then in the shell:

$ ./gradlew saveClassPathToFile
$ export CLASSPATH=`cat classpath.txt`
$ java com.example.MyEntryPoint
...

Upvotes: 2

Cleber Jorge Amaral
Cleber Jorge Amaral

Reputation: 1442

You can use gradle/gradlew command for that:

./gradlew dependencies --configuration compileClasspath

or for the runtime classpath:

./gradlew dependencies --configuration runtimeClasspath

Upvotes: 3

user3167916
user3167916

Reputation: 299

sourceSets.main.compileClasspath.asPath

For printing, you can write below the line in your task:

println "Classpath = ${sourceSets.main.compileClasspath.asPath}";

Upvotes: 11

Jules
Jules

Reputation: 15199

With gradle v4 I was unable to get either of the above options to work, but using --debug and grep classpath did find the information.

Upvotes: 3

Holger Brandl
Holger Brandl

Reputation: 11192

Or add println configurations.runtime.resolve() to your build.gradle.

Upvotes: 3

judoole
judoole

Reputation: 1422

The simplest would be to set log level to info using --info

If you would like to not browse through the output you could add a line similar to this inside your JavaExec task

doFirst{
  sourceSets.main.runtimeClasspath.each { println it}
}

Upvotes: 17

Related Questions