如何从代理后面使用sbt?

sup*_*pyo 81 sbt

如何配置sbt以使用代理?

例如,我的生成定义需要连接到GitHub上,用于指定连接参数http.proxy,http.proxyPort,user,和password.

我如何将这些设置传递给sbt?

当我在家工作时,是否有一种简单的方法可以在代理/无代理设置之间切换?

Fai*_*aiz 129

sbt 尊重http代理设置的常用环境变量:

export JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=yourserver -Dhttp.proxyPort=8080 -Dhttp.proxyUser=username -Dhttp.proxyPassword=password"
Run Code Online (Sandbox Code Playgroud)

(当然,假设是Unix(Linux/OSX等).在Windows上你可以%JAVA_OPTS%像往常一样在Windows中设置相同的环境变量().)

然后sbt像往常一样运行:

sbt
Run Code Online (Sandbox Code Playgroud)

在代理/无代理之间切换应该是设置一个小脚本,你可以随时"啜饮"它.

陷阱

  • 不要在yourserver值中包含"http://"
  • 不要在yourserver值中包含端口
  • 你可能也想要包括https.proxyHost,https.proxyPort因为很多东西都适用于https
  • 如果您的代理需要身份验证,除非它只使用基本身份验证,否则请不要尝试,因为SBT不支持其他任何操作.还要注意清除环境变量的短信凭证!请务必使用不会创建跟踪文件的文本编辑方法从.bash_history中删除命令(技术上您应该shredsrm整个文件).如果您使用的是Windows,请不要担心,您的安全性已经搞砸了,您不能再做任何伤害.

  • 在我搞清楚之后 - 我意识到在我的情况下我必须使用HTTPS java系统参数`-Dhttps.proxyHost`和`-Dhttps.proxyPort`! (6认同)
  • +1然而,在Windows 7上,从命令提示符我不得不使用`set JAVA_OPTS = -Dhttp.proxyHost = yourserver -Dhttp.proxyPort = 8080 -Dhttp.proxyUser = username -Dhttp.proxyPassword = password`来使其工作. (3认同)
  • 对我来说不起作用,我一直得到"你的代理需要身份验证",但它无法解决问题.我落后于传统的NTLM :( (3认同)

Jac*_*ski 25

sbt 与通常配置其他基于JVM的项目的方式相比,它以相当标准的方式工作.

sbt实际上是两个"子系统" - 发射器和核心.通常xsbt.boot.Boot在核心启动之前执行我们都知道的功能(有些甚至更喜欢).

因此,您应该如何执行sbt,说明如何为HTTP,HTTPS和FTP网络流量设置代理.

以下是可以为任何Java应用程序设置的可用属性的完整列表,包括指示Java API通过代理路由通信的sbt:

  • HTTP_PROXY
  • http_proxy_user
  • http_proxy_pass
  • http.proxyHost
  • 把http.proxyPort
  • http.proxyUser
  • http.proxyPassword

http以上替换为httpsftp获取服务的属性列表.

某些sbt脚本用于JAVA_OPTS设置代理设置-Dhttp.proxyHost以及-Dhttp.proxyPort其他脚本(如上所列).请参阅Java Networking and Proxies.

某些脚本使用自己的方式来设置代理配置SBT_OPTS,.sbtopts或者(仅在Windows上)%SBT_HOME%\conf\sbtconfig.txt.您可以使用它们专门设置sbt以使用代理,而其他基于JVM的应用程序根本不受影响.

sbt命令行工具:

# jvm options and output control
JAVA_OPTS          environment variable, if unset uses "$java_opts"
SBT_OPTS           environment variable, if unset uses "$default_sbt_opts"
.sbtopts           if this file exists in the current directory, it is
                   prepended to the runner args
/etc/sbt/sbtopts   if this file exists, it is prepended to the runner args
-Dkey=val          pass -Dkey=val directly to the java runtime
-J-X               pass option -X directly to the java runtime 
                   (-J is stripped)
-S-X               add -X to sbt's scalacOptions (-S is stripped)
Run Code Online (Sandbox Code Playgroud)

这里有一段摘录sbt.bat:

@REM Envioronment:
@REM JAVA_HOME - location of a JDK home dir (mandatory)
@REM SBT_OPTS  - JVM options (optional)
@REM Configuration:
@REM sbtconfig.txt found in the SBT_HOME.
Run Code Online (Sandbox Code Playgroud)

小心sbtconfig.txt,仅仅适用于Windows .当您使用cygwin该文件时,不会咨询,您将不得不求助于使用其他方法.

我正在使用带有以下脚本的sbt:

$JAVA_HOME/bin/java $SBT_OPTS -jar /Users/jacek/.ivy2/local/org.scala-sbt/sbt-launch/$SBT_LAUNCHER_VERSION-SNAPSHOT/jars/sbt-launch.jar "$@"
Run Code Online (Sandbox Code Playgroud)

该脚本的要点是使用从源构建的最新版本的sbt(这就是我使用的原因/Users/jacek/.ivy2/local/org.scala-sbt/sbt-launch/$SBT_LAUNCHER_VERSION-SNAPSHOT/jars/sbt-launch.jar)和$SBT_OPTS属性作为将JVM属性传递给JVM sbt使用的方法.

上面的脚本让我在MacOS X上的命令行上设置代理,如下所示:

SBT_OPTS="-Dhttp.proxyHost=proxyhost -Dhttp.proxyPort=9999" sbt
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,有很多方法可以为sbt设置代理,所有这些方法都可以归结为为JVM sbt使用设置代理.


blu*_*sky 11

我用过(这是一个unix环境):

export SBT_OPTS="$SBT_OPTS -Dhttp.proxyHost=myproxy-Dhttp.proxyPort=myport"
Run Code Online (Sandbox Code Playgroud)

这对我的设置不起作用:

export JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=myproxy-Dhttp.proxyPort=myport"
Run Code Online (Sandbox Code Playgroud)

在sbt.sh文件中:

JAVA_OPTS          environment variable, if unset uses "$java_opts"
SBT_OPTS           environment variable, if unset uses "$default_sbt_opts"
Run Code Online (Sandbox Code Playgroud)

但显然使用SBT_OPTS而不是JAVA_OPTS


小智 11

在Windows环境中,只需在sbt/sbtconfig.txt中添加以下行

-Dhttp.proxyHost=PROXYHOST 
-Dhttp.proxyPort=PROXYPORT 
-Dhttp.proxyUser=USERNAME 
-Dhttp.proxyPassword=XXXX
Run Code Online (Sandbox Code Playgroud)

或Https等价物(感谢评论)

-Dhttps.proxyHost=PROXYHOST 
-Dhttps.proxyPort=PROXYPORT 
-Dhttps.proxyUser=USERNAME 
-Dhttps.proxyPassword=XXXX
Run Code Online (Sandbox Code Playgroud)

  • 只要我在sbtconfig.txt中添加了另一行与*https*等效属性,这对我有用.我使用了与相应http属性完全相同的值.因此:-Dhttps.proxyHost = PROXYHOST -Dhttps.proxyPort = PROXYPORT -Dhttps.proxyUser = USERNAME -Dhttps.proxyPassword = XXXX (3认同)
  • 重要说明:不再有效!你必须使用`sbt/conf/sbtopts`文件. (3认同)

小智 9

对于Windows用户,请输入以下命令:

set JAVA_OPTS=-Dhttp.proxySet=true -Dhttp.proxyHost=[Your Proxy server] -Dhttp.proxyPort=8080
Run Code Online (Sandbox Code Playgroud)

  • 在我的情况下,我必须添加https的设置...`code` set JAVA_OPTS = -Dhttp.proxySet = true -Dhttp.proxyHost = <Proxy Server> -Dhttp.proxyPort = <Port> -Dhttp.proxyUser = <用户名> -Dht tp.proxyPassword = <密码> -Dhttps.proxySet = true -Dhttps.proxyHost = <代理服务器> -Dhttps.proxyPort = <端口> -Dhttps.proxyUser = <用户名> -Dhttp s.proxyPassword = <密码>`代码` (3认同)

Kin*_*ian 6

提供一个适用于所有Windows用户的答案:

将以下内容添加到sbtconfig.txt(C:\ Program Files(x86)\ sbt\conf)

-Dhttp.proxyHost=XXXXXXX -Dhttp.proxyPort=YYYY -Dhttp.proxySet=true -Dhttps.proxyHost=XXXXXXX -Dhttps.proxyPort=YYYY -Dhttps.proxySet=true
Run Code Online (Sandbox Code Playgroud)

XXXXXXX替换为您的proxyHost,将YYYY替换为您的proxyPort.

如果您收到错误"无法找到或加载主类",则需要设置JAVA_HOME:

set JAVA_HOME=C:\Progra~1\Java\jdkxxxxxx
Run Code Online (Sandbox Code Playgroud)

在64位窗口上时,使用:

Progra~1 ='程序文件'

Progra~2 ='程序文件(x86)'