Why can't VSCode detect this project structure generated by gradle init?

I’m new to Gradle and I’ve generated a Gradle application project using the gradle init. It’s working fine when I run gradle run, however, VSCode shows the error

The declared package “console.menu” does not match the expected package “app.src.main.java.console.menu”

I know it has something to do with classpath, but I don’t know how to fix it. Is this a VSCode problem? Or there is something I can do with Gradle to get rid of this error as well? E.g., maybe there’s a configuration I can put in build.gradle to help VSCode realize the source structure of this project? By the way, this is an “application” project.

I’m not a VSCode user, but I’m guessing you need to import your project as a Gradle project so that VSCode knows what type of project it is. Currently it’s thinking your root directory is a java source directory. Once you tell VSCode this is a Gradle project, it should determine that “app/src/main/java” is a java source directory.

Most probably you’re right. I guess it’s because the default source path the vscode java plugin expects is different, so I have to somehow change it, but I have issues doing that, so I’ve opened an issue here: (Unsupported operation. Please use build.gradle file) How to change the default source path in Gradle projects? · Issue #2159 · redhat-developer/vscode-java · GitHub.
I’ll mark your response as the solution since this doesn’t seem to be a Gradle issue. Thank you.

It looks like the Java Language Support Plugin has gradle integration. Have you installed/configured this plugin?