jbang icon indicating copy to clipboard operation
jbang copied to clipboard

Downloading dependencies under proxy

Open aghasemi opened this issue 4 years ago • 13 comments

Hi,

On my work laptop, JBang cannot download dependencies when under corporate proxy. Interestingly, JDK is downloaded without a problem. I guess it is because JDK and dependencies are downloaded through two different channels (JBang proper vs Maven?) where one reads http_* environment variables and the other doesn't. Is there an environment variable I can set to fix this for apparently Maven, that is used under the hood for downloading dependencies? MAVEN_OPTS and JAVA_TOOL_OPTS did not work, and I prefer not to create a settings.xml file in the Maven home.

Many thanks

aghasemi avatar Sep 22 '21 08:09 aghasemi

does it work when you set it via settings.xml? if that does not work then no amount of env var to change it will fix it.

users reports JAVA_TOOL_OPTS works here https://github.com/jbangdev/jbang/discussions/671 or system proxies https://github.com/jbangdev/jbang/issues/547#issuecomment-734154630

maxandersen avatar Sep 23 '21 22:09 maxandersen

jbang's proxy support looks broken.

As org.apache.maven.wagon.providers.http.LightweightHttpsWagon.openConnection() is actually used for making the HTTP connection (via sun.net HttpClient), it ignores system proxy configuration. Instead, it looks for the proxy configuration within the org.eclipse.aether.repository.RemoteRepository.RemoteRepository but jbang fails to set a proxy in the Repository's builder.

patric-r avatar Mar 28 '22 14:03 patric-r

I can confirm that the two solutions mentioned before do not work.

Thanks @patric-r for the feedback, that's very useful! You're not able to provide a fix by any chance as well, are you? :wink:

quintesse avatar Mar 28 '22 15:03 quintesse

Btw, JBang doesn't deal directly with the Aether API but uses Shrinkwrap, so we have to figure out how to set a proxy for that.

quintesse avatar Mar 28 '22 15:03 quintesse

@quintesse Yes, I noticed that as well. IMHO dev.jbang.dependencies.DependencyUtil.resolveDependenciesViaAether() looks like a good start for dealing with the proxy.

For sensible defaults, it make sense to either use the system proxy or maven defaults (e.g. .m2/settings.xml). BTW, is there a reason why jbang uses a customized version of shrinkwrap? This feels a little bit "unusual" (not to say hacky...).

patric-r avatar Mar 28 '22 16:03 patric-r

looks like a good start for dealing with the proxy.

Indeed, the problem is how. There doesn't seem to be anything in the API that deals with Proxies (at least the last time I looked).

is there a reason why jbang uses a customized version of shrinkwrap?

The explanation for that can be found in this PR: https://github.com/jbangdev/jbang/pull/673

quintesse avatar Mar 28 '22 18:03 quintesse

I also just doubly verified that setting the proxy in settings.xml makes the mvn command use it but it does not affect the behavior of jbang.

quintesse avatar Mar 28 '22 20:03 quintesse

same issue here

gwentey avatar Oct 13 '23 12:10 gwentey

Which issue? Settings.xml not working or?

maxandersen avatar Oct 13 '23 17:10 maxandersen

Any issues with proxies should go away once we decide to switch to MIMA.

quintesse avatar Oct 14 '23 00:10 quintesse

Any issues with proxies should go away once we decide to switch to MIMA.

What is MIMA? :)

aghasemi avatar Oct 20 '23 09:10 aghasemi

MIMA is what is coming in via this PR https://github.com/jbangdev/jbang/pull/1604

It is where jbang will be able to use more recent setup of maven's artifact resolver.

maxandersen avatar Oct 20 '23 13:10 maxandersen

Yeah, but later I realized that will only fix the proxy issues for artifact resolving/downloading, not for the other http requests we make. So that's still something we should definitely fix in our code.

quintesse avatar Oct 20 '23 23:10 quintesse