maven集成nexus伺服服务实现项目快速自动化构建与发布

16 篇文章 2 订阅

前言

在前面的博客centos7案例实战——Nexus3伺服仓库服务器搭建中已经详细讲解了如何在本地搭建自己的maven伺服仓库nexus,本节内容是关于如何在本地使用maven集成nexus伺服服务从而实现项目快速自动化构建与发布。

正文

  • 修改本地maven配置文件settings.xml,加入nexus配置
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
  <!-- 本地仓库存储地址 -->
  <localRepository>E:\maven_repo</localRepository>

  <!-- nexus服务账号信息,用于本地jar发布到伺服服务器使用-->
  <servers>
	<server>
      <id>releases</id>
      <username>admin</username>
      <password>admin</password>
    </server>

    <server>
        <id>snapshots</id>
        <username>admin</username>
        <password>admin</password>
    </server>
  </servers>

  <!-- nexus伺服仓库镜像地址,用于获取maven依赖包 -->
  <mirrors>
	<mirror>
		<id>public</id>
		<name>public</name>
		<mirrorOf>*</mirrorOf>
		<url>http://192.168.110.42:8081/repository/maven-public/</url>
	</mirror>

	<mirror>
		<id>releases</id>
		<name>releases</name>
		<mirrorOf>releases</mirrorOf>
		<url>http://192.168.110.42:8081/repository/maven-releases/</url>
	</mirror>

	<mirror>
		<id>snapshots</id>
		<name>snapshots</name>
		<mirrorOf>snapshots</mirrorOf>
		<url>http://192.168.110.42:8081/repository/maven-snapshots/</url>
	</mirror>
  </mirrors> 

  <!-- maven环境-->
  <profiles>
	<profile>
		<id>ht</id>
		<activation> 
			<activeByDefault>true</activeByDefault> 
			<jdk>1.8</jdk> 
		</activation> 
		<properties> 
			<maven.compiler.source>1.8</maven.compiler.source> 
			<maven.compiler.target>1.8</maven.compiler.target>
			<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> 
			<encoding>UTF-8</encoding> 
		</properties> 
        <!--工件仓库配置属性-->
        <repositories>
            <repository>
                <id>ht</id>
                <name>ht nexus Repository</name>
                <url>http://192.168.110.42:8081/repository/maven-public/</url>
                <layout>default</layout>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
        </repositories>
        <!--插件仓库配置属性-->
        <pluginRepositories>
            <pluginRepository>
                <id>ht</id>
                <name>ht nexus plugin Repository</name>
                <url>http://192.168.110.42:8081/repository/maven-public/</url>
                <layout>default</layout>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </pluginRepository>
		</pluginRepositories>
	</profile>	
  </profiles>

  <!-- 激活maven使用的环境 -->
  <activeProfiles>
	<activeProfile>ht</activeProfile>
  </activeProfiles>
</settings>

  • idea集成maven配置,使用配置伺服环境的maven

  • 本地maven项目直接使用伺服仓库地址获取项目依赖包,增加此处配置会优先使用此处配置获取项目依赖包 
<repositories>
        <repository>
            <id>public</id>
            <name>public</name>
            <url>http://192.168.110.42:8081/repository/maven-public/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
</repositories>

  • 本地项目配置伺服地址,实现本地项目发布到伺服仓库,供第三方使用

ps:此处配置的伺服仓库id要与maven配置中settings.xml的serverid一致,保证能通伺服仓库的授权验证

<!--伺服发布地址-->
<distributionManagement>
        <repository>
            <id>releases</id>
            <name>releases</name>
            <url>http://192.168.110.42:8081/repository/maven-releases/</url>
        </repository>

        <snapshotRepository>
            <id>snapshots</id>
            <name>snapshots</name>
            <url>http://192.168.110.42:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
</distributionManagement>

  • 使用idea发布本地maven项目到nexus伺服仓库

  •  查看伺服仓库是否有本地打包发布后的项目工程文件

PS: pom版本号包含SNAPSHOT,例如0.0.1-SNAPSHOT,会将包打包到snapshots仓库,并且每次都会生成一个新的包,如果版本号不包含SNAPSHOT,则会打包到releases仓库,只会有一个包。​​​​​​​​​​​​​​

结语

本节内容到这里就结束了,我们下期见。。。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

厉害哥哥吖

您的支持是我创作下去的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值