Maven私服Nexus应用

简介: Maven私服Nexus应用

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 发布三方插件到私服

目录
相关文章
|
5月前
|
Java Linux Maven
Linux系统Docker部署Nexus Maven并实现远程访问本地管理界面
Linux系统Docker部署Nexus Maven并实现远程访问本地管理界面
168 3
|
5月前
|
Java Linux Maven
私有仓库工具Nexus Maven如何部署并实现远程访问管理界面
私有仓库工具Nexus Maven如何部署并实现远程访问管理界面
159 0
|
12月前
|
Java 测试技术 Apache
【Maven】常用命令、插件管理、私服nexus
【Maven】常用命令、插件管理、私服nexus
|
11月前
|
存储 Java Maven
maven在尝试访问nexus存储库时得到“未授权” Not authorized , ReasonPhrase:Unauthorized
maven在尝试访问nexus存储库时得到“未授权” Not authorized , ReasonPhrase:Unauthorized
546 0
|
16天前
|
Java 应用服务中间件 测试技术
Maven学习笔记(一):Maven基础(基于命令行的学习和应用)
Maven 是一款 Java 项目构建工具,主要用于管理 jar 包及其依赖关系。 本文主要了解Maven基础知识及基础应用,旨在为之后的进一步学习奠定基础。 内容上几近全为学习《尚硅谷2022版Maven教程》整理所得。 仅供参考。
192 80
Maven学习笔记(一):Maven基础(基于命令行的学习和应用)
|
2月前
|
敏捷开发 Java 持续交付
阿里云云效产品使用合集之maven仓库是否可以代替自建的Nexus
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
|
2月前
|
Java jenkins 持续交付
jenkins学习笔记之十七:使用插件及maven上传制品到nexus
jenkins学习笔记之十七:使用插件及maven上传制品到nexus
|
2月前
|
Java
pandora boot热点应用探索问题之maven-compiler-plugin耗时较长的问题如何解决
pandora boot热点应用探索问题之maven-compiler-plugin耗时较长的问题如何解决
|
4月前
|
IDE Java Linux
在Maven中设置JVM系统参数及Java应用调试实例
在Maven中设置JVM系统参数及Java应用调试实例
189 0
|
5月前
|
Java Maven 数据安全/隐私保护
Nexus【应用 01】上传jar包到私有Maven仓库的两种方法:手动 Upload 和 mvn deploy 命令(配置+操作流程)
Nexus【应用 01】上传jar包到私有Maven仓库的两种方法:手动 Upload 和 mvn deploy 命令(配置+操作流程)
1837 0