微服务项目,子模块比较多,为了更方便找到打包结果,使用maven-antrun-plugin插件,在package结束后,拷贝至目标目录
目录结构
demo
--a
pom.xml
--b
pom.xml
pom.xml
demo下的pom.xml 打包
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
子模块下的pom.xml 的打包
<build>
<plugins>
<!-- 把jar包拷贝到指定目录位置 -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<configuration>
<tasks>
<!--目标目录,可以根据子模块的目录深度,自行调整-->
<copy todir="../target/${artifactId}">
<!-- 拷贝jar -->
<fileset dir="${project.build.directory}">
<include name="${artifactId}-${project.version}.jar" />
</fileset>
<!-- 拷贝配置文件 -->
<fileset dir="${project.build.directory}/classes">
<include name="application.yml" />
<include name="bootstrap.yml" />
</fileset>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>