-
maven-source-plugin 作用:
在构建过程中将项目的源代码进行打包,并作为一个jar文件附着在主构件上,在 pom.xml 中添加如下内容,使用 maven 生成 jar 的同时生成 sources 包 -
在 pom 中配置如下:
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>3.2.0</version>
<!-- 绑定source插件到Maven的生命周期,并在生命周期后执行绑定的source的goal --><executions><execution><!-- 绑定source插件到Maven的生命周期 --><id>attach-sources</id><phase>package</phase><!--在生命周期后执行绑定的source插件的goals --><goals><goal>jar-no-fork</goal></goals></execution></executions></plugin></plugins>
</build>
<phase>package</phase>
表示配置的插件在 Maven 构建的打包阶段执行- maven-source-plugin 提供项目自动将源码打包并发布的功能,在需要发布源码项目的 pom.xml 文件中添加即可
执行 mvn install,maven会自动将source install到repository
执行 mvn deploy,maven会自动将source deploy到remote-repository
mvn source:jar
,单独打包源码
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><executions><execution><id>attach-sources</id><goals><goal>jar</goal></goals></execution></executions>
</plugin>
- 注意:在多项目构建中,将 source-plugin 置于顶层或 parent 的 pom 中并不会发挥作用,须置于具体项目的pom中