社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
问题背景
使用springboot搭建多模块项目,pom引用依赖关系正常,编译正常情况。父项目maven package出现如下异常:
(1)第一类异常
[ERROR] 符号: 类 xxx
[ERROR] xxx.java:[7,38] 程序包xxx不存在
检查如下父pom以及其他非打包模块的pom文件是否存在如下插件,若有则删除或注释次插件(嵌套引用下插件造成编译异常)
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
通常仅在app工程中使用此插件(配合devtools设置热部署)
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--fork : 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
(2)第二类异常
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project webapp: There are test failures.
检查各个测试类是否打包跳过编译,可以使用@ignore注解(编译时跳过测试用例类)
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
public class CommonApplicationTests {
@Test
public void contextLoads() {
}
}
(3)第三类异常
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.4.RELEASE:repackage (default) on project webapp: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.4.RELEASE:repackage failed: Unable to find main class -> [Help 1]
spring-boot-maven-plugin插件会自动扫描启动类 并执行启动类main方法,所以检测使用插件工程下是否存在启动类(位置是否正确) 若没有添加启动类加@SpringBootApplication并重写main方法
@SpringBootApplication
public class WebappApplication {
public static void main(String[] args) {
SpringApplication.run(WebappApplication.class, args);
}
}
最后:maven clean 后 maven package
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!