如何在运行“mvn clean install”时修复WARNING消息

时间:2017-08-07 10:48:26

标签: java maven spring-boot

我正在使用jdk 8和maven版本3.3.9创建最新版本1.5.6.RELEASE的spring boot应用程序。运行mvn clean install

时,我收到以下警告消息
[DEBUG] Looking up lifecyle mappings for packaging pom from ClassRealm[plexus.core, parent: null]
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.XXXX:foo:jar:1.0.0
[WARNING] 'parent.relativePath' of POM com.XXX:foo:1.0.0 (/home/user/parent/foo/pom.xml) points at com.XXX:parent instead of org.springframework.boot:spring-boot-starter-parent, please verify your project structure @ line 12, column 13
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.XXX:bar:jar:1.0.0
[WARNING] 'parent.relativePath' of POM com.XXX:bar:1.0.0 (/home/user/parent/bar/pom.xml) points at com.XXX:parent instead of org.springframework.boot:spring-boot-starter-parent, please verify your project structure @ line 12, column 13
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:

我的项目是一个多模块构建。目录结构是:

xxx-project
|-- pom.xml
|-- foo
|   |-- pom.xml
|-- bar
|   |-- pom.xml

我的foo / 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>com.xxx</groupId>
    <artifactId>foo</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>foo</name>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>com.xxx.foo.App</start-class>
        <java.version>1.8</java.version>
        <lombok.version>1.16.18</lombok.version>
        <log4jdbc.log4j2.version>1.16</log4jdbc.log4j2.version>
        <rest.assured.version>3.0.3</rest.assured.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-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.bgee.log4jdbc-log4j2</groupId>
            <artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
            <version>${log4jdbc.log4j2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>${rest.assured.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>springloaded</artifactId>
                        <version>${spring-loaded.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

</project>

上面的pom.xml是使用github的maven archetype spring-boot-blank项目生成的。

父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>com.XXX</groupId>
  <artifactId>parent</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <name>parent</name>
  <modules>
    <module>foo</module>
    <module>bar</module>
  </modules>
</project>

如何在编译源代码时解决此警告消息?

请提供您的意见。

1 个答案:

答案 0 :(得分:8)

问题出现是因为默认情况下Maven假定父pom在包含模块pom的父文件夹中找到。但是,在您的项目中似乎并非如此:您的父pom是 org.springframework.boot:spring-boot-starter-parent:1.5.6.RELEASE 而pom 父文件夹中的com.xxx:parent:1.0.0 仅用作模块的聚合器。

要解决此问题,您需要在模块poms中取消设置父声明中的相对路径,如下所示:

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