Rate This Document
Findability
Accuracy
Completeness
Readability

Spring-boot-gradle-plugin Failed to Pull Compilation Dependencies

Symptom

The message "UnKnownHostException" is displayed when "repo.maven.apache.org" is accessed during the Spring Boot compilation.

Key Process and Cause Analysis

The host is not mapped. Add proxy configurations to solve the problem.

Conclusion and Solution

  1. Open the GradleBuild.java file.
    vim ./spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java
  2. Press i to enter the insert mode and modify the following content.
    1. Add the following content after line 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";

      In the preceding example, 127.0.0.1 and 3128 indicate the IP address and port number of the proxy host. Replace them with the actual ones.

    2. Modify the content in line 121 as follows:
      BuildResult result = prepareRunner(newArguments).build();
    3. Add the following content after line 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";

      In the preceding example, 127.0.0.1 and 3128 indicate the IP address and port number of the proxy host. Replace them with the actual ones.

    4. Add the following content below line 140:
      return prepareRunner(newArguments).buildAndFail();

      Run the :set list command to check the format. Spaces are not allowed. Use Tab to indent the code.

  3. Press Esc, type :wq!, and press Enter to save the file and exit.
  4. Recompile Spring Boot.