effarig
(effarig)
March 10, 2021, 11:54am
1
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.
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html#org.gradle.api.tasks.JavaExec
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.
https://docs.gradle.org/current/userguide/application_plugin.html
Vampire
(Björn Kautler)
March 12, 2021, 11:41pm
4
I would replace runtimeClasspath.join( File.pathSeparator )
by runtimeClasspath.asPath
though
calvin
(taylor)
August 11, 2021, 2:25pm
5
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?
Vampire
(Björn Kautler)
August 11, 2021, 2:39pm
6
That’s not really related to this topic, so it would be better to open a separate one instead of hijacking this.
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.
calvin
(taylor)
August 11, 2021, 4:08pm
7
my apologies for apparent thread jacking,
I posted about my specific issue here:
I too am getting the error “…unknown property ‘com’”
I have a project that creates a custom wrapper which includes a script in init.d named artifactory.gradle
initscript{
Properties properties = new Properties()
properties.load(new File(getGradleUserHomeDir(), 'gradle.properties').newDataInputStream())
repositories {
maven {
url properties.artifactory_contextUrl + '/gradle-plugins-virtual'
credentials {
username = properties.artifactory_user
password = properties.artifacto…
I had already done scan; which didn’t list the classpath as far as I can tell, it only lists the jars resolved.
https://scans.gradle.com/s/53i7kib32qwry
So I came here when I searched for how to view the classpath.
Vampire
(Björn Kautler)
August 12, 2021, 8:34pm
8
You see it in the scan at “Build dependencies”