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
113 stars 45 forks source link

HTTP proxy settings doesn't work when wrapper downloading the Gradle distribution in vscode-gradle v3.13.5 #1457

Open nonicknamelala opened 7 months ago

nonicknamelala commented 7 months ago

My computer connects to the internet through http proxy http://127.0.0.1:8118

I set up the http proxy in GRADLE_USER_HOME/gradle.properties .

By my testings, the proxy settings in gradle.properties doesn't work for wrapper to download the Gradle distribution, it only works when the Gradle distribution runs the gradle tasks.

And I also set up the proxy of "http.proxy", "java.jdt.ls.vmargs", "java.import.gradle.jvmArguments" in vscode settings.json, they all do not work for the gradle plugin.

Some days ago, before vscode-gradle upgraded to v3.13.5, I added the jvm proxy options in gradle-server.bat from the extensions folder, the proxy settings works and wrapper can download the Gradle distribution successfully.

But after upgrading to v3.13.5, the proxy settings in gradle-server.bat doesn't work again.

I captured the the java process by the command of "jps -mlv" as below:

29080 com.github.badsyntax.gradle.GradleServer 14789 -Dfile.encoding=UTF-8 -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8118 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8118

19500 c:\Users\****\.vscode\extensions\vscjava.vscode-gradle-3.13.5\lib\gradle-language-server.jar -Dfile.encoding=utf8

You can see that gradle-server.bat didn't pass the jvm options to gradle-language-server.jar .

Is it possible to enable the proxy settings from GRADLE_USER_HOME/gradle.properties or "java.import.gradle.jvmArguments" for wrapper to download the Gradle distribution please?

jdneo commented 7 months ago

Hi @nonicknamelala, thank you for reporting the issue.

Would you mind to the following tests to help me understand the problem.

  1. Is your gradle wrapper works properly if directly running from commandline (remember to clean the distribution cache $GRADLE_USER_HOME/wrapper/dists, or you can just rename it to make it easier to recover)

  2. If you switch back to the previous version, start from which version it's not working anymore. You can switch back by clicking:

image

nonicknamelala commented 7 months ago

Hi @nonicknamelala, thank you for reporting the issue.

Would you mind to the following tests to help me understand the problem.

  1. Is your gradle wrapper works properly if directly running from commandline (remember to clean the distribution cache $GRADLE_USER_HOME/wrapper/dists, or you can just rename it to make it easier to recover)
  2. If you switch back to the previous version, start from which version it's not working anymore. You can switch back by clicking:

image

谢谢你的答复!我看你的地点显示上海,我就直接用中文回复吧。

我的wrapper下载的gradle地址是https://mirrors.cloud.tencent.com/gradle/gradle-8.5-bin.zip , 在直连外网的电脑上,比如家里的电脑,wrapper都可以正常下载gradle, 也不会报java 证书问题。但是在我用的公司电脑上,在系统级别被设置了http代理,用maven或gradle/wrapper下载腾讯云或阿里云仓库都会报证书问题。我曾经debug过,是因为这个系统级别的http代理会影响腾讯云或阿里云的证书验证(具体细节我不是很清楚,证据工具会显示一张公司证书和一张仓库服务器证书,需要导入keystore,而且每天都会变,这样会非常麻烦)。

所以后来我想了一个办法,在局域网内另开了一个http代理服务映射到本机(不映射也没问题),可以完美的避开系统级别的http代理。gradle的配置文件gradle.properties里设置的这个http代理对于gradle本身也可以完美的工作。但是gradle.properties里配置的http代理对wrapper不生效。

我之前的办法是在项目的gradlew.bat文件或vscode-gradle插件的gradle-server.bat 文件里手动设置虚拟机的http代理,虽然麻烦一点,但能工作。

但是最近不知道升级了什么,wrapper又突然无法下载gradle了,提示证书问题。命令行运行修改过的gradlew.bat是可以的,但是vscode启动时自动调用的gradle-server.bat的代理不生效了。我相信应该是vscode-gradle插件用wrapper下载gradle时启动了多个java进程,而且下载gradle的那个进程没有启用http代理参数。

不过后来我把java.import.gradle.wrapper.enabled设成了false,也能解决问题。我相信这个需求应该没多少人用,能解决最好,直接关掉也可以。

谢谢!

jenkinstest123 commented 5 months ago

Hi @jdneo .

I have the same problem. Tested with the last version. Tried like 10 olders version, but same problem.

WakelessSloth56 commented 5 months ago

I might have found the reason:

Command line used for starting the server (.vscode\extensions\vscjava.vscode-gradle-3.13.5\lib\gradle-server.bat):

@rem Execute gradle-server
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_SERVER_OPTS%  -classpath "%CLASSPATH%" com.github.badsyntax.gradle.GradleServer %CMD_LINE_ARGS%

As you can see, it uses the JAVA_EXE, DEFAULT_JVM_OPTS, JAVA_OPTS, GRADLE_SERVER_OPTS variables. Searching in the file reveals that, compared to the original script, JAVA_EXE also relates to the environment variable VSCODE_JAVA_HOME:

:findJavaFromJavaHome
if defined JAVA_HOME set _JAVA_HOME=%JAVA_HOME:"=%
if defined VSCODE_JAVA_HOME set _JAVA_HOME=%VSCODE_JAVA_HOME:"=%
set JAVA_EXE=%_JAVA_HOME%/bin/java.exe

Then check the source code:

https://github.com/microsoft/vscode-gradle/blob/cdad052f7bcd11baf3f8819ff05b2e86dbfe7dad/extension/src/server/serverUtil.ts#L18-L29

It only sets the VSCODE_JAVA_HOME environment variable, but does not set the environment variable for config java.import.gradle.jvmArguments, etc.

cypher256 commented 5 months ago

The following was my lack of knowledge. No problem.


Current https://github.com/microsoft/vscode-gradle/blob/cdad052f7bcd11baf3f8819ff05b2e86dbfe7dad/extension/src/server/GradleServer.ts#L53-L57

Isn't it necessary to specify the options name like below?

this.process = cp.spawn(`"${cmd}"`, args, {
    cwd: cwd,
    env: env,
    shell: true,
});

child_process.spawn(command[, args][, options]) https://nodejs.org/api/child_process.html#child_processspawncommand-args-options