maven多模块----子模块相互依赖打包时报错找不到类的解决方案

文章提供了在SpringBoot项目中处理模块依赖的配置方法。在被依赖的模块POM文件中添加特定的spring-boot-maven-plugin配置,使用classifierexec。而在其他模块,配置编译源和目标版本为1.8,并执行repackage目标进行打包。通过这种方式,可以正确地构建和安装模块以便依赖。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解决方案:

在被依赖的模块pom文件中加上如下配置:

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

其他模块:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
             <configuration>
          		<source>1.8</source>
          		<target>1.8</target>
        	</configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

注:如果你的配置文件就是如上配置,那么你需要在maven打包的时候,install一下,就可以依赖了

我在idea中点击右侧的maven标志,并进行run maven bulid报错:[INFO] --- jacoco:0.8.7:report (report) @ pureedgesim --- [INFO] Skipping JaCoCo execution due to missing execution data file. [INFO] [INFO] --- jar:3.2.0:jar (default-jar) @ pureedgesim --- [WARNING] JAR will be empty - no content was marked for inclusion! [INFO] [INFO] --- source:3.2.1:jar-no-fork (attach-sources) @ pureedgesim --- [INFO] No sources in project. Archive not created. [INFO] [INFO] --- javadoc:3.2.0:jar (attach-javadocs) @ pureedgesim --- [INFO] [INFO] --- install:3.1.2:install (default-install) @ pureedgesim --- [INFO] Installing D:\Users\KEN\K\testtest\PureEdgeSim-master\PureEdgeSim-master\pom.xml to C:\Users\KEN\.m2\repository\com\mechalikh\pureedgesim\5.3.0\pureedgesim-5.3.0.pom [INFO] Installing D:\Users\KEN\K\testtest\PureEdgeSim-master\PureEdgeSim-master\target\pureedgesim-5.3.0.jar to C:\Users\KEN\.m2\repository\com\mechalikh\pureedgesim\5.3.0\pureedgesim-5.3.0.jar [INFO] [INFO] --- deploy:3.1.2:deploy (default-deploy) @ pureedgesim --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.920 s [INFO] Finished at: 2025-03-27T17:35:53+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.1.2:deploy (default-deploy) on project pureedgesim: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::url parameter -> [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/MojoExecutionException Process finished with exit code 1
03-28
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值