Maven多模块项目包装错误

时间:2018-12-04 09:43:25

标签: java spring-boot maven-3 spring-boot-maven-plugin

我正在尝试使用Maven开发多模块项目。但是,当我想打包项目时,就会出错。

它表示程序包在Web类中不存在。我已经在“问与答”部分尝试过解决方案。但是没有用。您可以查看我的仓库并告诉我我做错了什么吗?

[INFO] 8 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] xguru .............................................. SUCCESS [  1.330 s]
[INFO] data ............................................... SUCCESS [  5.453 s]
[INFO] web ................................................ FAILURE [  0.746 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.064 s
[INFO] Finished at: 2018-12-04T12:15:14+03:00
[INFO] Final Memory: 48M/391M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:testCompile (default-testCompile) on project web: Compilation failure: Compilation failure:
[ERROR] /C:/Users/asus/IdeaProjects/xguru/web/src/test/java/com/alikaan/xguru/controller/OwnerControllerTest.java:[3,31] package com.alikaan.xguru.model does not exist
[ERROR] /C:/Users/asus/IdeaProjects/xguru/web/src/test/java/com/alikaan/xguru/controller/OwnerControllerTest.java:[4,33] package com.alikaan.xguru.service does not exist
[ERROR] /C:/Users/asus/IdeaProjects/xguru/web/src/test/java/com/alikaan/xguru/controller/OwnerControllerTest.java:[32,13] cannot find symbol
[ERROR] symbol:   class OwnerService
[ERROR] location: class com.alikaan.xguru.controller.OwnerControllerTest
[ERROR] /C:/Users/asus/IdeaProjects/xguru/web/src/test/java/com/alikaan/xguru/controller/OwnerControllerTest.java:[37,9] cannot find symbol
[ERROR] symbol:   class Owner
[ERROR] location: class com.alikaan.xguru.controller.OwnerControllerTest
[ERROR] /C:/Users/asus/IdeaProjects/xguru/web/src/test/java/com/alikaan/xguru/controller/OwnerControllerTest.java:[45,9] cannot find symbol
[ERROR] symbol:   class Owner
[ERROR] location: class com.alikaan.xguru.controller.OwnerControllerTest
[ERROR] /C:/Users/asus/IdeaProjects/xguru/web/src/test/java/com/alikaan/xguru/controller/OwnerControllerTest.java:[45,25] cannot find symbol
[ERROR] symbol:   class Owner
[ERROR] location: class com.alikaan.xguru.controller.OwnerControllerTest
[ERROR] /C:/Users/asus/IdeaProjects/xguru/web/src/test/java/com/alikaan/xguru/controller/OwnerControllerTest.java:[46,9] cannot find symbol
[ERROR] symbol:   class Owner
[ERROR] location: class com.alikaan.xguru.controller.OwnerControllerTest
[ERROR] /C:/Users/asus/IdeaProjects/xguru/web/src/test/java/com/alikaan/xguru/controller/OwnerControllerTest.java:[46,26] cannot find symbol
[ERROR] symbol:   class Owner
[ERROR] location: class com.alikaan.xguru.controller.OwnerControllerTest
[ERROR] -> [Help 1]
[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/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :web

Process finished with exit code 1

这是我的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.alikaan</groupId>
    <artifactId>xguru</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <modules>
        <module>data</module>
        <module>web</module>
    </modules>
    <packaging>pom</packaging>


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

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


    <properties>
        <start-class>com.alikaan.xguru.XguruApplication</start-class>
        <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-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <goals>install</goals>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

WEB:

<?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">
    <parent>
        <artifactId>xguru</artifactId>
        <groupId>com.alikaan</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>web</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.alikaan</groupId>
            <artifactId>data</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</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>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>2.23.4</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <!--Required to get circleCI working-->
                    <useSystemClassLoader>false</useSystemClassLoader>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

数据:

<?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">
    <parent>
        <artifactId>xguru</artifactId>
        <groupId>com.alikaan</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>data</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>2.23.4</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
    <build>
        <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <!--Note your version numbe might be different-->
                    <version>2.22.1</version>
                    <configuration>
                        <useSystemClassLoader>false</useSystemClassLoader>
                    </configuration>
                </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

2 个答案:

答案 0 :(得分:1)

我通过将此数据添加到数据pom来弄清楚

   <properties>
    <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
   </properties>

但是我不知道为什么它解决了我的问题。

答案 1 :(得分:0)

项目结构有问题。由于您的反应堆父级的父级工件是

LayerList

所有工件,包括<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.0.RELEASE</version> 模块工件都将执行此插件执行:

data

<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <mainClass>${start-class}</mainClass> </configuration> </plugin> 模块不应重新包装到胖子罐中,因为您不想将其作为Spring Boot应用程序执行。您想将其用作依赖项。

请勿将data用作反应堆父对象!而是将Spring Boot BOM导入您父母的spring-boot-starter-parent(更多here)中:

dependencyManagement

将此添加到父母的<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.1.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency>

pluginManagement

<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.1.0.RELEASE</version> </plugin> 的发票从您的父级移动到spring-boot-maven-plugin模块,这样仅web将被重新打包,而web则不会。

最后,从父目录调用data。 {@ {1}}是反应堆运行所必需的,因为必须将依赖项工件(mvn clean install)复制到本地Maven存储库(通常为install),然后才能被依赖项工件用作依赖项。 data-0.0.1-SNAPSHOT.jar模块。