简体   繁体   English

Maven pom.xml依赖项-调整

[英]Maven pom.xml dependencies - adjusting

I am starting using Maven build tool for Java projects. 我开始将Maven构建工具用于Java项目。 I have added maven to system path and I have 3.5.3 version. 我已经将maven添加到系统路径中,并且具有3.5.3版本。 I have to red tips in pom.xml file in Eclipse that something in this file is wrong. 我必须在Eclipse的pom.xml文件中使用红色提示,指出该文件中的内容有误。 I tried to find some resources and I tried to change versions as in the source I used and next then build but it didn't work I have such pom.xml file: 我试图找到一些资源,并且尝试更改版本,就像我使用的源代码一样,然后再构建,但是没有用,我有这样的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>

<groupId>authorization</groupId>
<artifactId>auth</artifactId>
<version>4.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>auth</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.5.3</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

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

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

Maven build output errors: Maven构建输出错误:

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for authorization:auth:4.1.0-SNAPSHOT: 
Failure to find org.springframework.boot:spring-boot-starter- 
parent:pom:3.5.3 in https://repo.maven.apache.org/maven2 was cached in the 
local repository, resolution will not be reattempted until the update 
interval of central has elapsed or updates are forced and 
'parent.relativePath' points at no local POM @ line 14, column 10
@ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project authorization:auth:4.1.0-SNAPSHOT 
(C:\Users\lukas\workspace\auth\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for authorization:auth:4.1.0-SNAPSHOT: 
Failure to find org.springframework.boot:spring-boot-starter- 
parent:pom:3.5.3 in https://repo.maven.apache.org/maven2 was cached in the 
local repository, resolution will not be reattempted until the update 
interval of central has elapsed or updates are forced and 
'parent.relativePath' points at no local POM @ line 14, 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

I have checked mvn -version command and it is 3.5.3. 我已经检查了mvn -version命令,它是3.5.3。 The issue in my opinion is the SNAPSHOT statement. 我认为问题在于SNAPSHOT声明。 but how to adjust everything properly? 但是如何正确调整一切呢? I have used gradle and now I am doing maven. 我用过gradle,现在正在做行家。

Change your pom to : 将pom更改为:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
    </parent>

If you check maven repo folder here https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/ you will see that the last version is 2.0.2.RELEASE 如果您在此处检查Maven repo文件夹https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/,您会看到最新版本是2.0.2.RELEASE

The version here is the version of the artifact that you want and not your Maven version (which is 3.5.3) 这里的版本是您想要的工件的版本,而不是您的Maven版本(即3.5.3)。

You can use this pom.xml file, and you won't face any issue, as I have tried and tested it out. 您可以使用此pom.xml文件,并且不会遇到任何问题,因为我已经尝试并对其进行了测试。

<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>
    <groupId>authorization</groupId>
    <artifactId>auth</artifactId>
    <version>4.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM