原始答案(使用Gradle 1.12和Spring Boot 1.0.x):
在
bootRunspring启动gradle这个插件的任务延长了gradle这个JavaExec任务。看到这个。
这意味着您可以通过添加以下命令来配置插件以使用代理:
bootRun { jvmArgs = "-Dhttp.proxyHost=xxxxxx", "-Dhttp.proxyPort=xxxxxx"}到您的构建文件。
当然,您可以使用
systemProperties代替
jvmArgs
如果要从命令行有条件地添加jvmArgs,则可以执行以下操作:
bootRun { if ( project.hasProperty('jvmArgs') ) { jvmArgs project.jvmArgs.split('\s+') }}gradle bootRun -PjvmArgs="-Dwhatever1=value1 -Dwhatever2=value2"更新的答案:
在使用 Spring Boot 1.2.6.RELEASE 和 Gradle 2.7
尝试上述解决方案后,我发现它无法正常工作,因为其中提到了一些注释。但是,可以进行一些小的调整以恢复工作状态。
新的代码是:
bootRun { jvmArgs = ["-Dhttp.proxyHost=xxxxxx", "-Dhttp.proxyPort=xxxxxx"]}对于硬编码的参数,以及
bootRun { if ( project.hasProperty('jvmArgs') ) { jvmArgs = (project.jvmArgs.split("\s+") as List) }}用于从命令行提供的参数



