maven私服介绍
maven私服它是一种远程仓库,他能够节省自己的外网宽带,加速maven构建,部署自己内部的第三方构建,提高稳定性等
当Maven需要下载构件的时候,它从私服请求,如果 私服上不存在该构件,则从外部远程仓库下载,缓存在私服上之后,再为Maven的下载请求提供服务。
我们配置好了maven私服之后就可以开始使用了
maven仓库的类型
hosted 类型的仓库,内部项目的发布仓库
releases 内部的模块中release模块的发布仓库
snapshots 发布内部的SNAPSHOT模块的仓库
3rd party 第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去
proxy 类型的仓库,从远程中央仓库中寻找数据的仓库
group 类型的仓库,组仓库用来为了方便我们开发人员而进行设置的仓库
配置
然后我们可以在本地配置的maven里配置maven私服,我们在我们本地的maven私服的settings中进行配置
在servers中配置server
<server>
<!--自己定义--发布版本-->
<id>nexus-releases</id>
<!-- maven私服的账号密码-->
<username>xxxx</username>
<password>xxxxxx</password>
</server>
<!--快照版本 -->
<server>
<id>nexus-snapshots</id>
<username>xxxxx</username>
<password>xxxxx</password>
</server>
又在profiles中配置仓库的地址
<profile>
<!--自己定义 -->
<id>dapao</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.8</jdk>
</activation>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<!--自己定义在repositories中id不能相同 -->
<id>nexus</id>
<!--配置仓库组地址 -->
<url>http://xxx:8080/repository/maven-public/</url>
<!-- 是否把他当作发布版本或者发布库-->
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<!-- 插件库跟上面一样-->
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://xxx:8080/repository/maven-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
然后我们可以启用这个配置
<activeProfiles>
<!-- profile中的id-- >
<activeProfile>dapao</activeProfile>
</activeProfiles>
我们就可以在我们项目中的pom.xml文件中
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>maven-releases</name>
发布仓库的地址
<url>xxxx/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>maven-snapshots</name>
快照仓库的地址
<url>xxxxxx</url>
</snapshotRepository>
</distributionManagement>
<build>
<!-- <plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>-->
<plugins>
<!--发布代码Jar插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!--发布源码插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
这样就可以把我的项目上传到maven私服了