maven多模块 pluginManagement

在使用maven多模块整合springboot项目时候,意外发现mvn install 报错提示main方法找不到
错误日志如下:

Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage failed: Unable to find main class

google之,发现很多都是提示类似问题可能是因为项目中多个main导致的,需要在pom.xml中配置

properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <start-class>org.roshan.Application</start-class>
</properties>

又或者

profiles>
    <profile>
        <id>profile1</id>
        <properties>
            <spring.boot.mainclass>com.detaysoft.Application</spring.boot.mainclass>
        </properties>
    </profile>
</profiles>

又或者

   <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <mainClass>${spring.boot.mainclass}</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>

然而,病没什么乱用.

所以经过一番排除之后,发现其实是plugin配置的问题,罪魁祸首就是

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

因为父项目中的pom.xml如上面配置,意思是直接试用plugin的意思,这里父类项目中直接应用maven-plugin.所以会去每个module中寻找main方法进行编译,一旦不需要run的module被检查到没有main方法 所以 哼哼…
解决方式2种:
1 直接在需要run的module里面配置maven-plugin
2. 想直接在parent-module中配置,可以用pluginManagement标签,表示声明插件变量,所有child-module都可以继承,也可以覆盖.

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

没了.

参考: https://stackoverflow.com/questions/42937577/unable-to-find-main-class-with-maven-on-spring-boot-project-in-eclipse

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值