maven打包上传到私有仓库的步骤
- 一、pom.xml引入
- 二、Maven的settings.xml
- 三、pom.xml中添加源码插件
- 四、执行发布命令
先准备私库地址:
http://localhost:8081/nexus3/repository/maven-releases
http://localhost:8081/nexus3/repository/maven-snapshots
假如现需要将私有的jar发布到私库,步骤过程如下:
一、pom.xml引入
如果发布到releases私库(与build标签平级放入)
<distributionManagement><repository><id>releases</id><url>http://localhost:8081/nexus3/repository/maven-releases/</url></repository></distributionManagement>
如果发布到snapshots私库(与build标签平级放入)
<distributionManagement><snapshotRepository><id>snapshots</id><url>http://localhost:8081/nexus3/repository/maven-snapshots/</url></snapshotRepository></distributionManagement>
二、Maven的settings.xml
在servers标签下增加如下配置,配置发布到私库的账号和密码(如nexus3的账号admin和密码admin123)
<server><id>releases</id><username>admin</username><password>admin123</password></server><server><id>snapshots</id><username>admin</username><password>admin123</password></server>
三、pom.xml中添加源码插件
<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version></properties>
<!-- 编译插件 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><encoding>${project.build.sourceEncoding}</encoding><source>${java.version}</source><target>${java.version}</target><compilerArgs><arg>-parameters</arg></compilerArgs></configuration></plugin><!-- Source attach plugin --><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>
四、执行发布命令
mvn clean deploy