问题适用于

1、多模块项目

2、模块之间有依赖关系

3、不使用maven私服(无maven私服环境)

多模块项目结构如下

demo

┣ demo-api (接口层jar包项目)

┣ demo-service (服务提供)

┣ demo-web (服务调用)

┣ pom.xml

(模块项目间需要引用api项目,如使用dubbo时)

单独模块项目打包可能会出现打包错误

解决办法

整个项目一起打包,也就是在项目根目录执行打包命令。

(上面的例子,在demo下执行)

mvn clean install -Dmaven.test.skip=true

Windows系统cmd下需要加引号,如:

mvn clean install "-Dmaven.test.skip=true"

-Dmaven.test.skip=true 为不执行测试用例,也不编译测试用例类

附:引入本地第三方包打包的方法

1、Spring Boot项目为例,在resources目录下创建lib目录,将第三方包放入其中。

2、pom.xml里添加依赖如下。

<dependency>
    <groupId>com.demo</groupId>
    <artifactId>demo-api</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/lib/demo-api-1.0-SNAPSHOT.jar</systemPath>
</dependency>

3、pom.xml的build中添加maven插件开启导入范围,会将外部引用的jar包打包到项目jar包里。

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <includeSystemScope>true</includeSystemScope>
            </configuration>
        </plugin>
    </plugins>
</build>
最后修改:2021 年 05 月 31 日 12 : 13 AM
如果觉得我的文章对你有用,请随意赞赏