现在有一个项目结构如下:
父项目project
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx.xxx</groupId> <artifactId>project</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <dependencyManagement> <dependencies> <dependency> <groupId>io.spring.platform</groupId> <artifactId>platform-bom</artifactId> <version>Brussels-SR4</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <modules> <module>../projectA</module> <module>../projectB</module> <module>../projectC</module> </modules>
子项目projectA继承自父项目project
<modelVersion>4.0.0</modelVersion>
<artifactId>projectA</artifactId>
<parent>
<groupId>com.xxx.xxx</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../project</relativePath>
</parent>
<dependencies>
... ...
</dependencies>
子项目projectB继承自父项目project,同时引入了projectA做为依赖
<modelVersion>4.0.0</modelVersion>
<artifactId>projectB</artifactId>
<parent>
<groupId>com.xxx.xxx</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../project</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.xxx.xxx</groupId>
<artifactId>projectA</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
... ...
</dependencies>
子项目projectC继承自父项目project,同时引入了projectB做为依赖
<modelVersion>4.0.0</modelVersion>
<artifactId>projectC</artifactId>
<parent>
<groupId>com.xxx.xxx</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../project</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.xxx.xxx</groupId>
<artifactId>projectB</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
... ...
</dependencies>
现在要打包,直接在project上执行clean compile package打出的包无法运行,需要修改projectC(客户写的源码)的pom.xml文件
... ...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.3.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>demo</finalName>
</build>
然后在project上执行上述命令,打出的jar名字是demo.jar,运行:java -jar demo.jar即可