无法使用Spring Boot构建Maven项目

时间:2019-01-24 18:37:46

标签: java maven spring-boot

我试图构建Maven示例Spring Boot项目。我从https://start.spring.io/生成了Spring Boot项目。我做了Maven更新。当我使用pom.xml命令在Spring Tool Suite IDE中运行mvn clean install时,出现以下错误。

错误

[INFO] Scanning for projects...
[INFO] Downloading from : https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.2.RELEASE/spring-boot-starter-parent-2.1.2.RELEASE.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.luv2code.springboot.demo:mycoolapp:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.1.2.RELEASE from/to central (https://repo1.maven.org/maven2): connect timed out and 'parent.relativePath' points at wrong local POM @ line 5, column 10
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.luv2code.springboot.demo:mycoolapp:0.0.1-SNAPSHOT (C:\Users\nicolas\Dev\workspace\mycoolapp\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.luv2code.springboot.demo:mycoolapp:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.1.2.RELEASE from/to central (https://repo1.maven.org/maven2): connect timed out and 'parent.relativePath' points at wrong local POM @ line 5, column 10 -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

我的pom.xml和Settings.xml在下面

Pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.2.RELEASE</version>
    <!-- <relativePath/> lookup parent from repository -->
</parent>
<groupId>com.luv2code.springboot.demo</groupId>
<artifactId>mycoolapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mycoolapp</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Settings.xml

<?xml version="1.0" encoding="UTF-8"?>


<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 
http://maven.apache.org/xsd/settings-1.0.0.xsd">

<localRepository>C:/Users/nicolas/Dev/repo</localRepository>




<pluginGroups>

</pluginGroups>


<proxies>

</proxies>


<servers>

</servers>


<mirrors>

</mirrors>


<profiles>



    <profile>
        <id>securecentral</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <!--Override the repository (and pluginRepository) "central" from 
the
           Maven Super POM -->
        <repositories>
            <repository>
                <id>central</id>
                <url>https://repo1.maven.org/maven2</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>central</id>
                <url>https://repo1.maven.org/maven2</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </pluginRepository>
        </pluginRepositories>
    </profile>

</profiles>


</settings>

2 个答案:

答案 0 :(得分:1)

我能够使用您的pom.xml构建项目,请尝试使用此配置:

<settings>
  ...

  <profiles>
    <profile>
      <id>central</id>
      <repositories>
        <repository>
          <id>central</id>
          <name>central</name>
          <url> http://central.maven.org/maven2/</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>central</activeProfile>
  </activeProfiles>

  ...
</settings>

也如@BreakingBenjamin所指出的那样,用您的代理配置补充设置:

<proxies>
  <proxy>
    <active>true</active>
    <protocol>http</protocol>
    <host>mywonderfulproxy.com</host>
    <port>8080</port>
  </proxy>
</proxies>

如果您已经这样做了,请用更新的settings.xml

来补充您的答案

答案 1 :(得分:0)

通过在settings.xml中添加以下代理,我能够成功构建应用程序

  <proxies>
   <proxy>
    <id>example-proxy</id>
    <active>true</active>
    <protocol>http</protocol>
    <host>proxy.example.com</host>
    <port>8080</port>
    <username>proxyuser</username>
    <password>somepassword</password>
    <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
   </proxy>
 </proxies>