How can I print a parseable run time classpath?

I managed to build a Java Gradle project, and I’m now trying to run it from the command line. For that, I’d need gradle to print the the runtime dependencies.

If I do:

gradle dependencies --configuration runtimeClasspath

This prints out a decorated tree of dependencies, which is rather difficult and precarious to parse. What I was expecting is something more neat, like Maven:

mvn dependency:build-classpath

Please can someone help?

You can create a Gradle task to execute your application using the JavaExec task class.

If you really just want to print out a classpath, this should help get you going:

task printRuntimeClasspath {
    def runtimeClasspath = sourceSets.main.runtimeClasspath
    inputs.files( runtimeClasspath )
    doLast {
        println runtimeClasspath.join( File.pathSeparator )

Also, I should mention the application plugin, which adds a run task and some additional support for packaging.

I would replace runtimeClasspath.join( File.pathSeparator ) by runtimeClasspath.asPath though :slight_smile:

say in the case of an error; eg. “failed to load plugin:…”
How could one see the classpath to verify the plugin is available to be loaded?

That’s not really related to this topic, so it would be better to open a separate one instead of hijacking this. :wink:
A first step would be to use --stacktrace to see the actual error that happened.
The class path you want to see should be visible from buildEnvironment task I think, or nicer from a build scan.

my apologies for apparent thread jacking,

I posted about my specific issue here:

I had already done scan; which didn’t list the classpath as far as I can tell, it only lists the jars resolved.

So I came here when I searched for how to view the classpath.

You see it in the scan at “Build dependencies”