Reputation: 10464
A question for the VS Code wizards:
I have a Gradle project where I run main
methods from various class files from the command line. My build.gradle
file (under the project root) looks like this:
plugins {
id 'application'
}
repositories {
...
}
dependencies {
...
}
java {
toolchain ...
}
application {
// Define a dummy main class because we run main classes in various source files
mainClass = '....console.DontUsePlainRun'
}
tasks.register("run-ToolA", JavaExec) {
jvmArgs = ...
group = ApplicationPlugin.APPLICATION_GROUP
classpath = sourceSets.main.runtimeClasspath
mainClass = '....ToolA'
}
tasks.register("run-ToolB", JavaExec) {
jvmArgs = ...
group = ApplicationPlugin.APPLICATION_GROUP
classpath = sourceSets.main.runtimeClasspath
mainClass = '....ToolB'
}
...
I run the main
methods of the tool classes on the command line like this:
$ gradle run-ToolA
$ gradle run-ToolB
...
This works perfectly!
However, for debugging I would like to run thee classes in VS Code via the Gradle for Java plugin. I have installed it and VS Code seems to pick up that my project is a Gradle one, but when I look at the Gradle Projects panel my run tasks don't show up:
How can I make my run tasks show up and then debug them in VS Code?
Upvotes: 4
Views: 563
Reputation: 511
A typo error in the build.gradle file caused this issue for me. If you have a Gradle: Build Error displayed in the bottom panel, your Gradle tasks will not show.
Upvotes: 1
Reputation: 79
I recently had the same problem in an existing project. Suddenly the gradle tasks were no longer available on the Gradle Projects menu in VS Code. I wasn't able to get the tasks to display but I was able to run my fatJar task by opening a cmd terminal in VSCode and using the following command:
gradlew fatJar
I'm using Visual Studio Code Version 1.92.0.
My build.gradle contains task:
task fatJar(type: Jar) {
archiveFileName = "${project.name}.jar"
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
I hope this helps.
Upvotes: 0