我正在尝试用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>网站:
<?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>发布于 2018-12-04 13:22:25
我通过向数据pom添加以下内容来解决这个问题
<properties>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>发布于 2019-07-16 15:58:55
这个项目的结构有问题。因为您的反应堆父级的父工件是
<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>不应该将data模块重新打包到一个胖jar中,因为您不希望将它作为Spring应用程序执行。您希望将其用作依赖工件。
不要使用spring-boot-starter-parent作为反应堆的父级!相反,将Spring导入父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不会被打包。
最后,从父目录调用mvn clean install。install是反应堆工作所必需的,因为依赖工件(data-0.0.1-SNAPSHOT.jar)必须复制到本地Maven存储库(通常是~/.m2/repositories/...),然后才能被web模块用作依赖项。
https://stackoverflow.com/questions/53609881
复制相似问题