比如我們想要把項目通過maven生產源碼包和文檔包並發布到自己的私服上,有兩個maven插件可以做到這些工作,一個是maven-source-plugin,另一個是maven-javadoc-plugin。
一:首先在你的項目的pom.xml文件中加入如下配置:
如果有parent 只需在parent 中的pom.xml 中配置,沒有則在本項目的pom.xml 配置即可
<distributionManagement>
<repository>
<id>nexus-release</id>
<url>http://192.168.0.247/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://192.168.0.247/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<!-- 生成sources源碼包的插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
<!--意思是在什么階段打包源文件-->
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
在maven 的setting.xml 中配置用戶名和密碼:
<servers>
<server>
<username>deployment</username>
<password>deploy123</password>
<id>nexus-release</id>
</server>
<server>
<username>deployment</username>
<password>deploy123</password>
<id>nexus-snapshots</id>
</server>
</servers>
上門的id和pom.xml 中對應distributionManagement-> repository 的ID ,用戶名和密碼需要在nexus 中配置
二:執行maven命令,mvn clean package,執行完成后就會生成相應的jar包文件
三:如果你還需要發布到自己的私服,那么就再執行一條命令:mvn deploy就可以發布到你自己的私服上了,這樣同項目組的人員就可以查看你的項目的源碼和文檔了!
執行 mvn install,maven會自動將source install到repository 。
執行mvn deploy –Dmaven.test.skip=true,maven會自動將source deploy到remote-repository 。