---
title: Spring-boot-gradle-plugin编译依赖拉取问题的解决方法
description: "编译Spring Boot过程中需要访问“repo.maven.apache.org”，提示“UnknownHostException”。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengwebs/ecosystemEnable/SpringBoot/kunpengspringboot_02_0012.html
sourcePath: /source/zh/kunpengwebs/ecosystemEnable/SpringBoot/kunpengspringboot_02_0012.html
indexId: 0c8bb3fe57f2418a55d31d7504b016a5df5c4357e9c2c953429ac2b5ec78193380
---
# Spring-boot-gradle-plugin编译依赖拉取问题的解决方法

#### 问题现象描述

编译Spring Boot过程中需要访问“repo.maven.apache.org”，提示“UnknownHostException”。


#### 关键过程、根本原因分析

Host未建立映射关系，可以通过增加代理配置解决。


#### 结论、解决方案及效果

1. 打开GradleBuild.java文件。

```
vim ./spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java
```


2. 按“i”进入编辑模式，修改如下内容。

  a. 在第114行后新增如下内容。

```
String[] newArguments = new String[arguments.length + 4];
System.arraycopy(arguments, 0, newArguments, 0, arguments.length);
newArguments[arguments.length] = "-Dhttp.proxyHost=
127.0.0.1
";
newArguments[arguments.length + 1] = "-Dhttp.proxyPort=
3128
";
newArguments[arguments.length + 2] = "-Dhttps.proxyHost=
127.0.0.1
";
newArguments[arguments.length + 3] = "-Dhttps.proxyPort=
3128
";
```


    其中，127.0.0.1和3128分别表示代理主机的IP地址和端口，操作时请根据实际代理环境配置。

  b. 修改第121行为如下内容。

```
BuildResult result = prepareRunner(newArguments).build();
```


  c. 在第135行后新增如下内容。

```
String[] newArguments = new String[arguments.length + 4];
System.arraycopy(arguments, 0, newArguments, 0, arguments.length);
newArguments[arguments.length] = "-Dhttp.proxyHost=
127.0.0.1
";
newArguments[arguments.length + 1] = "-Dhttp.proxyPort=
3128
";
newArguments[arguments.length + 2] = "-Dhttps.proxyHost=
127.0.0.1
";
newArguments[arguments.length + 3] = "-Dhttps.proxyPort=
3128
";
```


    其中，127.0.0.1和3128分别表示代理主机的IP地址和端口，操作时请根据实际代理环境配置。

  d. 第140行的下一行添加如下内容。

```
return prepareRunner(newArguments).buildAndFail();
```


    请使用:set list检查格式。不能出现空格，请使用Tab作为代码缩进。

3. 按“Esc”键，输入:wq!，按“Enter”保存并退出编辑。
4. 重新编译Spring Boot。
