vscode-gradle icon indicating copy to clipboard operation
vscode-gradle copied to clipboard

gradle java project gives errors when parameters passed to gradle process

Open skaluva opened this issue 7 months ago • 12 comments

Extension Name: vscode-gradle Extension Version: 3.15.0 OS Version: Windows 11 VSCode version: 1.91.0

Describe the bug I have a simple gradle project which uses gradle version 7.5.1 and java version JDK 17. I have custom gradle plugin in build.gradle which expects -PMY_PARAM=abc to be passed when gradle commands gets executed on the project. For example: from command line i have to pass like this: gradle build -PMY_PARAM=ABC to make the build successful. This need to be passed for all tasks. Same i'm trying to achieve in vscode using vscode-gradle extension but im failed to do that despite all trials. Below is my settings.json

{
    "java.import.gradle.home": "C:\\XYZ\\gradle-git-7.5.1",
    "java.import.gradle.user.home": "C:\\Users\\XYZ\\.gradle751",
    "java.import.gradle.version": "",
    "java.import.gradle.wrapper.enabled": false,
    //"java.gradle.buildServer.enabled":"off",
    "java.import.gradle.java.home": "C:\\XYZ\\zulu17.46.20-sa-jdk17.0.9-win_x64",
    "java.jdt.ls.java.home": "C:\\XYZ\\zulu17.46.20-sa-jdk17.0.9-win_x64",
    "java.configuration.runtimes": [
      {
        "name": "JavaSE-1.7",
        "path": "C:\\Program Files\\Zulu\\zulu-7",
      },
      {
        "name": "JavaSE-1.8",
        "path": "C:\\XYZ\\jdk1.8.0_271"
      },
      {
        "name": "JavaSE-11",
        "path": "C:\\XYZ\\zulu11.60.20-sa-jdk11.0.17-win_x64",
      },
      {
        "name": "JavaSE-17",
        "path": "C:\\XYZ\\zulu17.46.20-sa-jdk17.0.9-win_x64",
        "default": true
      }
    ],
    "gradle.nestedProjects": true,
    "security.workspace.trust.untrustedFiles": "open",
    "workbench.iconTheme": "vscode-icons",
    "java.jdt.ls.vmargs": "",
    "java.import.gradle.jvmArguments": "-PMY_PARAM=abc", //tried here, it works during 'gradle configure' stage but java project initialization fails with below error
    "java.import.gradle.arguments": "", //i tried adding the same here but its not getting passed to gradle commands and so gradle tasks execution failing with errors as that prop not found.
    "terminal.integrated.copyOnSelection": true,
    "workbench.settings.applyToAllProfiles": [
      "terminal.integrated.copyOnSelection"
    ],
    "maven.executable.path": "C:\\XYZ\\apache-maven-3.6.3\\bin\\mvn.cmd",
    "maven.executable.preferMavenWrapper": false
    }

If i pass param to java.import.gradle.jvmArguments getting below error:

java.util.concurrent.CompletionException: org.eclipse.lsp4j.jsonrpc.ResponseErrorException: Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/7.5.1/userguide/gradle_daemon.html
Process command line: C:\\XYZ\softwares\zulu17.46.20-sa-jdk17.0.9-win_x64\bin\java.exe -PMY_PARAM=abc --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\\XYZ\softwares\gradle-git-7.5.1\lib\gradle-launcher-7.5.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.5.1
Please read the following process output to find out more:
-----------------------
Unrecognized option: -PMY_PARAM=abc
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

	at java.base/java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:413)
	at java.base/java.util.concurrent.CompletableFuture.join(CompletableFuture.java:2118)
	at com.microsoft.gradle.bs.importer.Utils.getBuildTargetsMappedByProjectPath(Utils.java:47)
	at com.microsoft.gradle.bs.importer.GradleBuildServerProjectImporter.importProjects(GradleBuildServerProjectImporter.java:266)
	at com.microsoft.gradle.bs.importer.GradleBuildServerProjectImporter.importToWorkspace(GradleBuildServerProjectImporter.java:179)
	at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.importProjects(ProjectsManager.java:164)
	at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.initializeProjects(ProjectsManager.java:126)
	at org.eclipse.jdt.ls.core.internal.handlers.InitHandler$1.runInWorkspace(InitHandler.java:277)
	at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.eclipse.lsp4j.jsonrpc.ResponseErrorException: Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/7.5.1/userguide/gradle_daemon.html
Process command line: C:\\XYZ\softwares\zulu17.46.20-sa-jdk17.0.9-win_x64\bin\java.exe -PMY_PARAM=abc --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\\XYZ\softwares\gradle-git-7.5.1\lib\gradle-launcher-7.5.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.5.1
Please read the following process output to find out more:
-----------------------
Unrecognized option: -PMY_PARAM=abc
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.


If i set the param to "java.import.gradle.arguments": "-PMY_PARAM=abc", its not getting passed at all to gradle tasks causing gradle configure stage failures.

I'm banging my head to fix this for the past few weeks. I'm not sure how to get this done. I really wanted to use vscode for all my future projects. But these unknown errors blocking me. Please suggest.

skaluva avatar Jul 24 '24 07:07 skaluva