Maven私服Nexus应用

Maven私服Nexus应用

目录

Maven私服Nexux应用

1 配置settings.xml 文件

2 了解用户权限

3 pom.xml 文件

4 发布本地工程到私服

5 发布三方插件到私服


1 配置settings.xml 文件

要在 Maven 工程中使用私服,需要提供私服配置信息。

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<localRepository>D:/repositories</localRepository>
<!--Maven 是否需要和用户交互以获得输入。如果 Maven 需要和用户交互以获得输入,则设置成 true, 反之则应为 false。默认为 true。--> 
<interactiveMode>true</interactiveMode>
<!--表示 Maven 是否需要在离线模式下运行。如果构建系统需要在离线模式下运行,则为 true,默认为 false。 --> 
<offline>false</offline>
<!--当插件的组织 Id(groupId)没有显式提供时,供搜寻插件组织 Id(groupId)的列表。该元素包含一个 pluginGroup 元素列表,每个子元素包含了一个组织 Id(groupId)。当我们使用某个插件,并且没有在命令行为其提供组织 Id(groupId)的时候,Maven 就会使用该列表。 
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
<pluginGroup>org.jenkins-ci.tools</pluginGroup>
</pluginGroups>

<proxies>
</proxies>
<!--配置服务端的一些设置。一些设置如安全证书不应该和 pom.xml 一起分发。这种类型的信息应该存在于构建服务器上的 settings.xml 文件中。--> 
<servers>
<server>
<!-- server 的 id 必须和 pom.xml 文件中的仓库 id 一致 -->
<!--这是 server 的 id(注意不是用户登陆的 id),该 id 与 distributionManagement 中
repository 元素的 id 相匹配。-->
<id>nexus-releases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
<!--根据环境参数来调整构建配置的列表。--> 
<profiles>
<profile>
<id>jdk-1.7</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.7</jdk>
</activation>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
</properties>
</profile>
<profile>
<id>zgl</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.7</jdk>
</activation>
<repositories>
<!-- 私有库配置 -->
<repository>
<!-- 私有库 id -->
<id>nexus</id>
<!-- 私有库地址 -->
<url>http://192.168.120.158:8081/nexus/content/groups/public/</url>
<!-- 私有库是否支持 releases 版本 -->
<releases>
<enabled>true</enabled>
</releases>
<!-- 私有库是否支持 snapshots 版本 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!-- 插件库配置,具体含义私有库配置 -->
<pluginRepository>
<id>nexus</id>
<url>http://192.168.120.158:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<!-- 激活 profile -->
<activeProfiles>
<!-- 根据 profile 的 id 标签值激活指定的内容 -->
<activeProfile>zgl</activeProfile>
<activeProfile>jdk-1.7</activeProfile>
</activeProfiles>
</settings>

1.1 创建项目

此时就到我们自己的私服去下载东西

2 了解用户权限

这里我选用deployment折中,权限正好

3 pom.xml 文件

在顶级的 maven 父工程中定义。所有子工程自动导入依赖。

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group</groupId>
<artifactId>project</artifactId>
<version>1.0</version>

<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.120.158:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.120.158:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

 

4 发布本地工程到私服

在 Maven 工程的 maven build 中,输入命令 deploy,即可实现发布工程信息到私服。如果同版本工程可能多次发布,需要修改 Nexus 配置。

此时要允许Redeploy

5 发布三方插件到私服

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赵广陆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值