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

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

Open nonicknamelala opened this issue 2 years ago • 5 comments

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?

nonicknamelala avatar Dec 05 '23 01:12 nonicknamelala

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

jdneo avatar Dec 05 '23 02:12 jdneo

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,也能解决问题。我相信这个需求应该没多少人用,能解决最好,直接关掉也可以。

谢谢!

nonicknamelala avatar Dec 05 '23 07:12 nonicknamelala

Hi @jdneo .

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

jenkinstest123 avatar Jan 30 '24 12:01 jenkinstest123

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:

  • GradleServer.ts start() -> serverUtil.ts getGradleServerEnv()

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.

WakelessSloth56 avatar Feb 07 '24 03:02 WakelessSloth56

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

cypher256 avatar Feb 09 '24 08:02 cypher256

Hi @nonicknamelala, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.

Suggested solutions

• Ensure you use Gradle’s documented proxy properties in %GRADLE_USER_HOME%/gradle.properties (not just http.proxyHost):

systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=8118
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=8118
# for artifact downloads (if you need auth):
systemProp.http.proxyUser=<user>
systemProp.http.proxyPassword=<pass>
systemProp.https.proxyUser=<user>
systemProp.https.proxyPassword=<pass>

References:

  • Gradle proxy docs: https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy
  • redhat-developer/vscode-java#176 (comment): https://github.com/redhat-developer/vscode-java/issues/176#issuecomment-304119046

• If the wrapper VM still ignores gradle.properties, inject proxy JVM args via an env var or your OS startup script. For example:

export JAVA_TOOL_OPTIONS="-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8118 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8118"

• As a temporary workaround, you can also set:

// settings.json
"java.jdt.ls.vmargs": "-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8118 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8118",
"java.import.gradle.jvmArguments": "-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8118 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8118"

but note that the current Gradle wrapper in vscode-gradle may not forward these flags for the distribution download itself.

• If you get a corrupted ZIP (e.g. ZipException), delete your local wrapper cache and retry:

rm -rf ~/.gradle/wrapper/dists/gradle-*-bin/

Reference: https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/321#issuecomment-319689015

No exact duplicate found.

Other references with low confidence

• Failure to install Gradle distribution behind proxy (vscode-java#383): suggests using -DGRADLE_HOME via java.jdt.ls.vmargs or running a separate Gradle install. https://github.com/redhat-developer/vscode-java/issues/383#issuecomment-349749020

The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!

github-actions[bot] avatar Nov 05 '25 10:11 github-actions[bot]