下载、安装Nexus
Nexus OSS
http://www.sonatype.org/nexus/archived/
配置 Repositories
nexus里可以配置3种类型的仓库,分别是proxy、hosted、group
proxy是远程仓库的代理。比如说在nexus中配置了一个central repository的proxy,当用户向这个proxy请求一个artifact,这个proxy就会先在本地查找,如果找不到的话,就会从远程仓库下载,然后返回给用户,相当于起到一个中转的作用。
hosted是宿主仓库,用户可以把自己的一些构件,deploy到hosted中,也可以手工上传构件到hosted里。比如说oracle的驱动程序,ojdbc6.jar,在central repository是获取不到的,就需要手工上传到hosted里
group是仓库组,在maven里没有这个概念,是nexus特有的。目的是将上述多个仓库聚合,对用户暴露统一的地址,这样用户就不需要在pom中配置多个地址,只要统一配置group的地址就可以了。
配置 Central Repository
Repository Policy:Release
Remote Storage Location:https://repo1.maven.org/maven2/
Download Remote Indexes:True
Override Local Storage Location:Nexus仓库地址(以仓库名称区分)
配置 Releases Repository\(项目组内部的发布版\)
Repository Policy:Release
Deployment Policy:Allow Redeploy
Override Local Storage Location:Nexus仓库地址(以仓库名称区分)
配置 3rd party Repository\(第三方jar\)
Repository Policy:Release
Deployment Policy:Allow Redeploy
Override Local Storage Location:Nexus仓库地址(以仓库名称区分)
配置 Snapshots Repository\(项目组内部的快照\)
Repository Policy:Snapshot
Deployment Policy:Allow Redeploy
Override Local Storage Location:Nexus仓库地址(以仓库名称区分)
Deployment Policy这个选项,一般Snapshots会配置成允许,而Releases和3rd party会设置为禁止。
配置 Group Repository
Releases、3rd party、Snapshots、Central、Apache Snapshots、Codehaus Snapshots
配置用户密码
在Security-->Users中配置,在deployment用户上点击右键,选择Set Password,然后设置一个密码。
在用户机器上配置settings.xml
Nexus权限控制
配置镜像仓库,id为nexus、url为Group Repository地址、mirrorOf为central
IDE中的设置
安装Maven插件
在Installations中安装自己的Maven,不使用IDE自带的Maven
在Preferences-->Maven-->User Settings中,点击Update Settings,加载刚才我们对settings.xml的更改
修改settings.xml中的本地仓库位置
Maven编译插件
<plugin>
<!-- 编译Java文件 -->
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<!-- 生成源代码 -->
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- 执行测试并配置参数 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<!-- 处理资源文件 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<!-- 生成war包 -->
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<version>3.0</version>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
依赖下载路径及远程部署仓库地址
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo1.maven.org/maven2/</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<!-- 远程部署到仓库 -->
<distributionManagement>
<repository>
<id>deploymentRepo-Releases</id><!-- id 需与 Nexus 权限控制的id一致 -->
<url>http://10.10.10.100:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>deploymentRepo-Snapshots</id><!-- id 需与 Nexus 权限控制的id一致 -->
<url>http://10.10.10.100:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>