Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to switch build tool after initial import of mixed gradle/maven project #3567

Closed
FieteO opened this issue Apr 8, 2024 · 5 comments · Fixed by #3573
Closed

Option to switch build tool after initial import of mixed gradle/maven project #3567

FieteO opened this issue Apr 8, 2024 · 5 comments · Fixed by #3573
Assignees

Comments

@FieteO
Copy link
Contributor

FieteO commented Apr 8, 2024

When opening a project for the first time, the user is presented with a dialog to choose between maven or gradle when more than one build tool is present.
Correct me if I am wrong, but afterwards there is no easy way to switch to the other build tool.

Environment
  • Operating System: Ubuntu 23.10
  • JDK version: openjdk version "17.0.10" 2024-01-16
  • Visual Studio Code version: 1.88.0
  • Java extension version: 1.29.0
Steps To Reproduce
  1. Select the build tool when opening the project for the first time
  2. ??

Please attach a sample project reproducing the error

P.S Only tangentially related: The Language Support for Java Output is printing the following error when opening the project using maven:

[Error - 9:33:05 PM] Apr 8, 2024, 9:33:05 PM Error occured while building workspace. Details: 
 message: The project was not built since its build path is incomplete. Cannot find the class file for de.danielbechler.diff.ObjectDiffer. Fix the build path then try building this project; code: 0; resource: /home/ubu/development/oss/rewrite-recipe-starter;
 message: The type de.danielbechler.diff.ObjectDiffer cannot be resolved. It is indirectly referenced from required type org.openrewrite.TreeVisitor; code: 16777563; resource: /home/ubu/development/oss/rewrite-recipe-starter/src/main/java/com/yourorg/AppendToReleaseNotes.java; line: 1

Is that an issue with a faulty project setup for maven in the openrewrite project or perhaps an error on the language support side?
It is compiling fine with running maven and gradle from the command line and when choosing gradle as the build tool

@rgrunber
Copy link
Member

rgrunber commented Apr 9, 2024

Once a selection is made, the option is stored in the workspace state database :

} else if (activeBuildTool.toLocaleLowerCase().includes("maven")) {
// Here we do not persist it in the settings to avoid generating/updating files in user's workspace
// Later if user want to change the active build tool, just directly set the related settings.
clientOptions.initializationOptions.settings.java.import.gradle.enabled = false;
context.workspaceState.update(ACTIVE_BUILD_TOOL_STATE, "maven");
} else if (activeBuildTool.toLocaleLowerCase().includes("gradle")) {
clientOptions.initializationOptions.settings.java.import.maven.enabled = false;
context.workspaceState.update(ACTIVE_BUILD_TOOL_STATE, "gradle");
, so we could probably restore the option to choose by resetting the value in
export function cleanupProjectPickerCache(context: ExtensionContext) {
context.workspaceState.update(PICKED_BUILD_FILES, undefined);
context.workspaceState.update(BUILD_TOOL_FOR_CONFLICTS, undefined);
context.workspaceState.update(IMPORT_METHOD, undefined);
}
(and probably rename the method) , which gets triggered by "Clean Workspace Cache" (quick-pick from server status bar) or "Java: Clean Java Language Server Workspace" (command palette).

With that said, can you try what's mentioned in that comment, and just set :

{
"java.import.gradle.enabled": "...",
"java.import.maven.enabled": "..."
}

in your workspace (.vscode/settings.json) settings file ?

as a workaround ?

Update: Also, yes, if https://github.com/moderneinc/rewrite-recipe-starter is the project, then I'm seeing the same error. @snjeza any idea why ?

@FieteO
Copy link
Contributor Author

FieteO commented Apr 9, 2024

Okay, generally changing the build tool works when setting either one of the

"java.import.gradle.enabled": false,
"java.import.maven.enabled": true

settings to true or false and then do a Java: Clean Language Server Workspace. Just reloading the window for instance is not enough to change it.

In terms of making this more accessible, maybe the Type in Java: Configure Runtimes could be made editable similar to how the Java version can be changed there:
image

@rgrunber
Copy link
Member

rgrunber commented Apr 9, 2024

I guess https://github.com/microsoft/vscode-java-pack/blob/main/src/java-runtime/index.ts could be updated to modify the active build tool for the particular workspace. @testforstephen , thoughts on this improvement ?

@testforstephen
Copy link
Collaborator

Pls note that Configure Runtime for Projects page is purely nodejs UI thing, no any Java logic. If we want to open the ability to reimport the workspace with different build tool there, this definitely requires language server to provide the command to do that.

Anyway, I think when you clean the language server workspace, Java extension should prompt and ask you to select the build tool again before importing mixed build tool workspace. If this is not the behavior, then it's a bug in vscode-java extension.

@rgrunber
Copy link
Member

Java: Clean Language Server Workspace should clear the saved build tool selection now.

@rgrunber rgrunber added this to the End April 2024 milestone Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants