microsoft / vscode-gradle

Manage Gradle Projects, run Gradle tasks and provide better Gradle file authoring experience in VS Code
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-gradle
MIT License
127 stars 53 forks source link

No tasks detected for Gradle #135

Closed aaronsteers closed 4 years ago

aaronsteers commented 4 years ago

Describe the bug

No tasks are appearing when I refresh the tasks view. From everything else I've seen, it looks like Gradle is working fine. I'm running Windows and I've tested (unsuccessfully) using the latest VS Code version on Windows native as well as running under WSL. Output below along with build.gradle content.

Disclaimer: I'm new to Gradle and also new to this extension.

To Reproduce

  1. created ./build.gradle file with the following text:
plugins {
    id "base"
}

task zip(type: Zip, description: "Archive project definition as a zip") {
    from "data"
    setArchiveFileName "project.zip"
}
  1. created ./settings.gradle with the following text:
rootProject.name = 'dataops-project-template'

(dataops-project-template is the name of the project and root directory)

  1. run gradle tasks and confirm zip is in the list.

  2. run ./gradlew version:

------------------------------------------------------------
Gradle 6.0.1
------------------------------------------------------------

Build time:   2019-11-18 20:25:01 UTC
Revision:     fad121066a68c4701acd362daf4287a7c309a0f5

Kotlin:       1.3.50
Groovy:       2.5.8
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.5 (Private Build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04)
OS:           Linux 4.19.84-microsoft-standard amd64

Expected behavior

Expected to see gradle tasks (at least my custom task zip) in the "Gradle Tasks" pane.

Screenshots

...

Environment (please complete the following information):

Output from "Gradle Tasks"

{"type":"GRADLE_PROGRESS","message":"Build"}
{"type":"GRADLE_PROGRESS","message":"Connecting to Gradle Daemon"}
{"type":"GRADLE_PROGRESS","message":"Build"}
{"type":"GRADLE_PROGRESS","message":"Run build"}
{"type":"GRADLE_PROGRESS","message":"Evaluate settings"}
{"type":"GRADLE_PROGRESS","message":"Run build"}
{"type":"GRADLE_PROGRESS","message":"Configure build"}
{"type":"GRADLE_PROGRESS","message":"Load projects"}
{"type":"GRADLE_PROGRESS","message":"Configure build"}
{"type":"GRADLE_PROGRESS","message":"Configure project :"}
{"type":"GRADLE_PROGRESS","message":"Configure build"}
{"type":"GRADLE_PROGRESS","message":"Run build"}
{"type":"GRADLE_PROGRESS","message":"Build model 'org.gradle.tooling.model.GradleProject' for root project 'dataops-project-template'"}
{"type":"GRADLE_PROGRESS","message":"Run build"}
{"type":"GRADLE_PROGRESS","message":"Build"}
{"type":"GRADLE_PROGRESS","message":"Deleting unused version-specific caches in C:\\Files\\Source\\dataops-project-template\\.gradle"}
{"type":"GRADLE_PROGRESS","message":"Build"}
{"type":"GRADLE_OUTPUT","message":"","outputType":"STDOUT"}

{"type":"GRADLE_OUTPUT","message":"\nCONFIGURE SUCCESSFUL in 72ms","outputType":"STDOUT"}

CONFIGURE SUCCESSFUL in 72ms
{"type":"GRADLE_PROGRESS","message":""}

{
    "type": "GRADLE_TASKS",
    "tasks": [
      {
        "name": "assemble",
        "group": "build",
        "path": ":assemble",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Assembles the outputs of this project."
      },
      {
        "name": "build",
        "group": "build",
        "path": ":build",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Assembles and tests this project."
      },
      {
        "name": "buildEnvironment",
        "group": "help",
        "path": ":buildEnvironment",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays all buildscript dependencies declared in root project 'dataops-project-template'."
      },
      {
        "name": "check",
        "group": "verification",
        "path": ":check",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Runs all checks."
      },
      {
        "name": "clean",
        "group": "build",
        "path": ":clean",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Deletes the build directory."
      },
      {
        "name": "components",
        "group": "help",
        "path": ":components",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays the components produced by root project 'dataops-project-template'. [incubating]"
      },
      {
        "name": "dependencies",
        "group": "help",
        "path": ":dependencies",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays all dependencies declared in root project 'dataops-project-template'."
      },
      {
        "name": "dependencyInsight",
        "group": "help",
        "path": ":dependencyInsight",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays the insight into a specific dependency in root project 'dataops-project-template'."
      },
      {
        "name": "dependentComponents",
        "group": "help",
        "path": ":dependentComponents",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays the dependent components of components in root project 'dataops-project-template'. [incubating]"
      },
      {
        "name": "help",
        "group": "help",
        "path": ":help",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays a help message."
      },
      {
        "name": "init",
        "group": "Build Setup",
        "path": ":init",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Initializes a new Gradle build."
      },
      {
        "name": "model",
        "group": "help",
        "path": ":model",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays the configuration model of root project 'dataops-project-template'. [incubating]"
      },
      {
        "name": "outgoingVariants",
        "group": "help",
        "path": ":outgoingVariants",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays the outgoing variants of root project 'dataops-project-template'."
      },
      {
        "name": "prepareKotlinBuildScriptModel",
        "group": null,
        "path": ":prepareKotlinBuildScriptModel",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": null
      },
      {
        "name": "projects",
        "group": "help",
        "path": ":projects",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays the sub-projects of root project 'dataops-project-template'."
      },
      {
        "name": "properties",
        "group": "help",
        "path": ":properties",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays the properties of root project 'dataops-project-template'."
      },
      {
        "name": "tasks",
        "group": "help",
        "path": ":tasks",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Displays the tasks runnable from root project 'dataops-project-template'."
      },
      {
        "name": "wrapper",
        "group": "Build Setup",
        "path": ":wrapper",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Generates Gradle wrapper files."
      },
      {
        "name": "zip",
        "group": null,
        "path": ":zip",
        "project": "dataops-project-template",
        "buildFile": "C:\\Files\\Source\\dataops-project-template\\build.gradle",
        "rootProject": "dataops-project-template",
        "description": "Archive project definition as a zip"
      }
    ]
  }

Does the bug still exist if you disable all other extensions?

I'm not sure how to test this but I tried disabling all task-related extentions and I still get the same result.

Additional context

Add any other context about the problem here.

badsyntax commented 4 years ago

Hi. Thanks for the bug report. I'm looking into this.

Can you confirm you do see the "Gradle Tasks" panel in the explorer like so?:

Screenshot 2020-01-01 at 00 54 37
badsyntax commented 4 years ago

From the logs you posted, the extension is able to correctly discover the tasks, so this is possibly just a UI rendering thing. Let me know if you see the "Gradle Tasks" panel at all.

I've attempted to replicate this issue without success (on Windows 10). To help me debugging this, can you provide a zip file with all the necessary files that demonstrates this issue? Thanks.

aaronsteers commented 4 years ago

Hi. Thanks for the bug report. I'm looking into this.

Can you confirm you do see the "Gradle Tasks" panel in the explorer like so?:

Screenshot 2020-01-01 at 00 54 37

Confirmed. This is exactly what I see in my left-hand panel.

aaronsteers commented 4 years ago

I've attempted to replicate this issue without success (on Windows 10). To help me debugging this, can you provide a zip file with all the necessary files that demonstrates this issue? Thanks.

Yes, I'll post back later with that zip of the files. If I have time, I would like to also try without any other extensions loaded - although I'm not sure how to do that quickly since I have 20+ extensions.

ndarilek commented 4 years ago

Hitting the exact same issue using Insiders build as of this morning under Linux. Tasks are detected as per the logs, the tasks tree is displayed, but no tasks are listed in it.

I'll see if I can assemble a reproduction at some point--this is happening on a work-related project that I can't share.

One thing I'll note is that I'm using a multi-workspace project. I have task auto-detection off in the root folder, but on in the sub-folder containing the Gradle project. We have a monorepo with lots of different projects, so hopefully this setup works, but I wonder if that might be why things aren't appearing? Very new to VSCode.

Thanks.

badsyntax commented 4 years ago

Hey, I've released a couple new extension versions. Are you still experiencing this issue?

aaronsteers commented 4 years ago

Hey, I've released a couple new extension versions. Are you still experiencing this issue?

Not sure yet, but will report back. Thanks!

Column01 commented 4 years ago

I'm experiencing this too. Running the latest extension version. It seems that restarting VS Code sometimes fixes it, but sometimes it just doesn't work. img

badsyntax commented 4 years ago

Thanks for the report @Column01. I've discovered that i'm not really handling errors very well when providing the gradle tasks to vscode. See this particular catch statement here:

https://github.com/badsyntax/vscode-gradle/blob/b257bebafe0e9cf8637d64268af7b4ec6d1e41da/src/tasks.ts#L140-L142

I will add better logging to surface the underlying issue here.

In the meantime, I don't suppose you can provide me a zip of this project (with private code removed)?

Column01 commented 4 years ago

Is there anything specific from the zip you'd need? I have the code hosted on github, but I'm not sure if I've excluded anything else you need. Here is the code (it's a minecraft mod)

badsyntax commented 4 years ago

This is perfect, thanks! Don't need a zip, i'll just clone. This project will possibly help me debug this issue easier, as i'm yet to replicate on my own projects.

Column01 commented 4 years ago

Just a note (not sure if it matters) The gradle wrapper is an older version (4.6 I believe). It's required since Forge uses old gradle methods that will not work on new versions.

badsyntax commented 4 years ago

@Column01 can you confirm you see the following error? (you need enable the "gradle.debug" setting)

Screenshot 2020-02-20 at 18 05 47

This looks like a different error to OP sadly. Thanks for the extra info about the version, I will look into a fix for this.

Column01 commented 4 years ago

I don't see that since the tasks are showing up for me now (Like I said, restarting VS Code sometimes fixes it)

Column01 commented 4 years ago

Also that appears to be a gradle error that doesn't come from your end.

badsyntax commented 4 years ago

In the cases where you get no tasks, are there any errors in the output panel?

(Yep i'm seeing a gradle error, doesn't mean i can't potentially prevent it from occurring, by changing how i use the tooling API for example.)

aaronsteers commented 4 years ago

Not sure if this is helpful, but this output was in my terminal under "1: Task - Gradle Task Server":

> Executing task: ".\gradle-tasks-server.bat" 63625 <

Gradle tasks server started
Could not fetch model of type 'GradleProject' using Gradle distribution 'https://services.gradle.org/distributions/gradle-6.1.1-bin.zip'.

And on hitting the "refresh" button, I also see the following in OUTPUT > Gradle Tasks:

[debug] CLIENT MESSAGE: {"getTasks":{"sourceDir":"c:\\Files\\Source\\slalom-people-data"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Build"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Connecting to Gradle Daemon"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Build"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Run build"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Evaluate settings"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Run build"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Configure build"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Load projects"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Configure build"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Configure project :"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Configure build"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Run build"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Build"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Deleting unused version-specific caches in C:\\Files\\Source\\slalom-people-data\\.gradle"}}
[debug] SERVER MESSAGE: {"progress":{"message":"Build"}}
[debug] SERVER MESSAGE: {"outputChanged":{"message":"","outputType":0}}
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\nFAILURE: Build failed with an exception.","outputType":0}}
[info] FAILURE: Build failed with an exception.
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\n","outputType":0}}
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\n* Where:","outputType":0}}
[info] * Where:
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\nBuild file 'C:\\Files\\Source\\slalom-people-data\\build.gradle' line: 14","outputType":0}}
[info] Build file 'C:\Files\Source\slalom-people-data\build.gradle' line: 14
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\n","outputType":0}}
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\n* What went wrong:","outputType":0}}
[info] * What went wrong:
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\nA problem occurred evaluating root project 'dataops-project-template'.","outputType":0}}
[info] A problem occurred evaluating root project 'dataops-project-template'.
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\n> .\\Dockerimage (The system cannot find the file specified)","outputType":0}}
[info] > .\Dockerimage (The system cannot find the file specified)
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\n","outputType":0}}
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\n* Try:","outputType":0}}
[info] * Try:
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\nRun with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.","outputType":0}}
[info] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\n","outputType":0}}
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\n* Get more help at https://help.gradle.org","outputType":0}}
[info] * Get more help at https://help.gradle.org
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\n","outputType":0}}
[debug] SERVER MESSAGE: {"outputChanged":{"message":"\nCONFIGURE FAILED in 241ms","outputType":0}}
[info] CONFIGURE FAILED in 241ms
[debug] SERVER MESSAGE: {"progress":{"message":""}}
[debug] SERVER MESSAGE: {"error":{"message":"Could not fetch model of type 'GradleProject' using Gradle distribution 'https://services.gradle.org/distributions/gradle-6.1.1-bin.zip'."}}
[error] Could not fetch model of type 'GradleProject' using Gradle distribution 'https://services.gradle.org/distributions/gradle-6.1.1-bin.zip'.
[debug] SERVER MESSAGE: {"getTasks":{"message":"Completed ACTION_GET_TASKS","tasksList":[]}}

UPDATE (2): There's a relative reference in the above to a file at ./Dockerimage (.\\Dockerimage in windows) which failed although the file was correctly in the project root. After replacing the relative reference with an absolute reference, I do get what looks like successful parsing in the OUTPUT window - but sadly the Gradle Tasks pane still does not populate with a task list.

UPDATE (3): FWIW, the above is from a single working folder (aka, not a multi-folder workspace).

badsyntax commented 4 years ago

@aaronsteers seems like a gradle project setup issue. Are you able to list tasks using the Gradle wrapper directly? Eg ".\gradlew.bat tasks --all"?

Drakmyth commented 4 years ago

In case it's helpful for anyone who finds this thread in the future, I was experiencing this same problem. No errors anywhere I could see, just no tasks would be detected.

In my case, it was due to me having added my gradlew executable in my workspace's files.exclude list so it wouldn't appear in the explorer. It seems this extension detects Gradle via the file explorer rather than looking in the root folder or allowing a custom detection path, so if you're hiding the gradle-related files it thinks there's no Gradle and won't show anything.

I'm not sure how common of a use case it is to hide those files, so I don't know how viable it would be to add a setting to control this behavior, but just in case anyone was experiencing the same problem and nothing currently in the thread helped, I wanted to detail what the solution was in my case.

badsyntax commented 4 years ago

@Drakmyth Thanks for this. Indeed, a "Gradle Project" is defined by having wrapper scripts at the root as described in https://github.com/badsyntax/vscode-gradle/blob/master/ARCHITECTURE.md The extension uses the standard vscode api's to detect files, it doesn't look at the file explorer per se. I'll see what i can do to workaround this with https://github.com/badsyntax/vscode-gradle/issues/485

To everyone else in this thread: I've released a bunch of new changes and a lot of functionality has changed, so I don't think it makes sense to try debug the original issues anymore.

Please try the latest version, and if you're still having issues, please review the Troubleshooting section in the README. If you're then still having issues, please create a new issue and I'd be more than happy to attempt to help, but I can't do so anymore in the context of this thread.