Maven

Bug收集

【软件】Java开发环境相关工具IDEA、JDK、Maven

Maven-相关书籍

Maven-资源

Maven简介

IDEA对3.6.2及以上版本存在兼容性问题,为避免冲突,IDEA中安装使用3.6.1版本

  • Maven的本质是一个项目管理工具,将项目开发和管理过程抽象成一个项目对象模型(POM)
  • POM(Project Object Model):项目对象模型

image-20220808185314825-2

阿里云镜像仓库、settings文件

<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>

settings.xml

<?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.home}/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.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
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<!--自定义本地仓库路径-->
<localRepository>/Users/zhangxin/.m2/repository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->

<!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false
<offline>false</offline>
-->

<!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>

<!-- proxies
| This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used.
|-->
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>

<!-- servers
| This is a list of authentication profiles, keyed by the server-id used within the system.
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|-->
<servers>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->

<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
</servers>

<!-- mirrors
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
|
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
| However, this repository may have problems with heavy traffic at times, so people have mirrored
| it to several places.
|
| That repository definition will have a unique id, so we can create a mirror reference for that
| repository, to be used as an alternate download site. The mirror site will be the preferred
| server for that repository.
|-->
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->

<mirror>
<id>alimaven-central</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>

<!--<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>ibiblio</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>
<mirror>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>-->

</mirrors>

<!-- profiles
| This is a list of profiles which can be activated in a variety of ways, and which can modify
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
| specific paths and repository locations which allow the build to work in the local environment.
|
| For example, if you have an integration testing plugin - like cactus - that needs to know where
| your Tomcat instance is installed, you can provide a variable here such that the variable is
| dereferenced during the build process to configure the cactus plugin.
|
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
| section of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular value for the property,
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
| Finally, the list of active profiles can be specified directly from the command line.
|
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
| repositories, plugin repositories, and free-form properties to be used as configuration
| variables for plugins in the POM.
|
|-->
<profiles>
<!-- profile
| Specifies a set of introductions to the build process, to be activated using one or more of the
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
| or the command line, profiles have to have an ID that is unique.
|
| An encouraged best practice for profile identification is to use a consistent naming convention
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
| This will make it more intuitive to understand what the set of introduced profiles is attempting
| to accomplish, particularly when you only have a list of profile id's for debug.
|
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
-->
<profile>
<id>jdk18</id>
<activation>
<jdk>1.8</jdk>
<activeByDefault>true</activeByDefault>
</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>
</properties>
</profile>

<!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
</profiles>

<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
</settings>

下载版:

Maven工程目录结构

image-20220808190351908

pom.xml(src同目录下创建)

<?xml version="1.0" encoding="UTF-8"?> 
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zx</groupId>
<artifactId>project-java</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency> </dependencies>
</project>

构建命令

  • mvn compile # 编译
  • mvn clean # 清理
  • mvn test # 测试
  • mvn package # 打包
  • mvn install # 安装到本地仓库

插件创建maven工程

  • 创建工程
mvn archetype:generate 
-DgroupId={project-packaging}
-DartifactId={project-name}
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false
  • 创建Java工程
mvn archetype:generate 
-DgroupId=com.zx
-DartifactId=java-project
-DarchetypeArtifactId=maven-archetype-quickstart
-Dversion=0.0.1-snapshot
-DinteractiveMode=false
  • 创建web工程
mvn archetype:generate 
-DgroupId=com.zx
-DartifactId=web-project
-DarchetypeArtifactId=maven-archetype-webapp
-Dversion=0.0.1-snapshot
-DinteractiveMode=false

Tomcat7插件

<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>80</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>

依赖传递冲突问题

  • 路径优先:当依赖中出现相同的资源时,层级越深,优先级越低,层级越浅,优先级越高
  • 声明优先:当资源在相同层级被依赖时,配置顺序靠前的覆盖配置顺序靠后的
  • 特殊优先:当同级配置了相同资源的不同版本,后配置的覆盖先配置的

image-20220808200234224

Maven排除依赖和可选依赖

可选依赖指对外隐藏当前所依赖的资源–不透明

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<optional>true</optional>
</dependency>

排除依赖指主动断开依赖的资源,被排除的资源无需指定版本一一不需要

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<exclusions>
<exclusion>
<groupId>org.hancrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>

Maven排除依赖和可选依赖

依赖范围

依赖的jar默认情况可以在任何地方使用,可以通过scope标签设定其作用范围
作用范围

  • 主程序范围有效(main文件夹范围内)

  • 测试程序范围有效(test文件夹范围内)

  • 是否参与打包(package指令范围内)

scope 主代码 测试代码 打包 范例
compile(默认) Y Y Y log4j
test Y junit
provided Y Y Servlet-api
runtime Y Jdbc

依赖访问传递性

带有依赖范国的资源在进行传递时,作用范围将受到影响

image-20220808201827738

生命周期与插件

项目构建生命周期:

Maven构建生命周期描述的是一次构建过程经历经历了多少个事件

image-20220808202050296

clean生命周期:

  • pre-clean 执行一些需要在clean之前完成的工作
  • clean 移除所有上一次构建生成的文件
  • post-clean 执行一些需要在clean之后立刻完成的工作

default构建生命周期

image-20220808202741995

site构建生命周期

  • pre-site 执行一些需要在生成站点文档之前完成的工作

  • site 生成项目的站点文档

  • post-site 执行一些需要在生成站点文档之后完成的工作,并且为部署做准备

  • site-deploy 将生成的站点文档部署到特定的服务器上

插件

  • 插件与生命周期内的阶段绑定,在执行到对应生命周期时执行对应的插件功能
  • 默认maven在各个生命周期上绑定有预设的功能
  • 通过插件可以自定义其他功能
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<phase>generate-test-resources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

分模块开发与设计

image-20220730201547634

ssm_pojo拆分

新建模块,拷贝原始项目中对应的相关内容到ssm_pojo模块中

  • 今实体类(User)
  • 配置文件(无)

ssm_dao拆分

新建模块,拷贝原始项目中对应的相关内容到ssmdao模块中

  • 数据层接口(UserDao)
  • 配置文件:保留与数据层相关配置文件(3个),注意:分页插件在配置中与SqlSessionFactoryBean绑定,需要保留
  • pom.xml:引入数据层相关坐标即可,删除springmvc相关坐标
    • spring
    • mybatis
    • spring整合mybatis
    • mysql
    • druid
    • pagehelper
    • 直接依赖ssm_pojo(ssm_pojo模块需install安装到本地仓库)

ssm_service拆分

新建模块,拷贝原始项目中对应的相关内容到ssm_service模块中

  • xxxService、xxxServiceImpl
  • 配置文件:保留与数据层相关配置
  • pom.xml:引入数据层相关坐标,删除springmvc相关坐标
    • spring
    • junit
    • spring整合junit
    • 直接依赖ssm_dao(ssm_dao模块需install安装到本地仓库)
    • 简接依赖ssm_pojo(因为ssm_dao引用了ssm_pojo)
    • 修改service模块spring核心配置文件名,添加模块名称,格式:applicationContext-service.xml
    • 修改dao模块spring核心配置文件名,添加模块名称,格式:applicationContext-dao.xml
    • 修改单元测试引入的配置文件名称,由单个文件修改为多个文件

ssm_controll拆分

新建模块(使用webapp模板),拷贝原始项目中对应的相关内容到ssm_controller模板中

  • 表现层控制器类与相关设置类(Usercontroller、异常相关…)
  • 配置文件:保留与表现层相关配置文件(1个)、服务器相关配置文件(1个)
  • pom.xml:引入数据层相关坐标即可,删除springmvc相关坐标
    • spring
    • springmvc
    • jackson
    • servlet
    • tomcat服务器插件
    • 直接依赖ssm_service(ssm_service模块需install安装到本地仓库)
    • 问接依赖ssm_dao、ssm_pojo

分模块开发小节

  • 模块中仅包含当前模块对应的功能类与配置文件
  • Spring核心配置根据模块功能不同进行独立制作
  • 当前模块所依赖的模块通过导入坐标的形式加入当前模块后才可以使用
  • web.xm需要加载所有的spring核心配置文件

聚合

作用:聚合用于快速构建maven工程,一次性构建过个项目/模块

制作方式:

1.创建一个空模块,打包类型定义为pom

<packaging>pom</packaging>

2.定义当前模块进行构建操作时关联的其他模块名称

<modules>
<module>../ssm controller</module>
<module>../ssm service</module>
<module>../ssm dao</module>
<module>../ssm pojo</module>
</modules>

注意事项:参与聚合操作的模块最终执行顺序与模块间的依赖关系有关,与配置顺序无关

继承

制作方式

作用:通过继承可以实现在子工程中沿用父工程中的配置

  • maven中的继承与Java中继承相似,在子工程中配置继承关系

制作方式:

  • 在子工程中声明其父工程坐标与对应的位置
<!--定义该工程的父工程-->
<parent>
<groupId>com.zx</groupId>
<artifactId>ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<!--填写父工程的pom文件-->
<relativePath>../ssm/pom.xml</relativePath>
</parent>

依赖定义

在父工程中定义依赖管理

<!--声明此处进行依赖管理-->
<dependencyManagement>
<!--具体的依赖-->
<dependencies>
<!--spring环境-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>

依赖使用

在子工程中定义依赖关系,无需声明依赖版本,版本参照父工程中依赖的版本

<!--导入资源文件pojo-->
<dependencies>
<!--spring环境-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>

继承的资源

image-20220809103816186

继承与聚合对比

作用:

  • 聚合用于快速构建项目
  • 继承用于快速配置

相同点:

  • 聚合与继承的pom.xml文件打包方式均为pom,可以将两种关系制作到同一个pom文件中
  • 聚合与继承均属于设计型模块,并无实际的模块内容

不同点:

  • 聚合是在当前模块中配置关系,聚合可以感知到参与聚合的模块有哪些
  • 继承是在子模块中配置关系,父模块无法感知哪些子模块继承了自己

属性类别

自定义属性

作用:等同于定义变量,方便统一维护

定义格式:

<!--定义自定义的属性-->
<properties>
<spring.version>5.1.9.RELEASE</spring.version>
<junit.version>4.12</junit.version>
</properties>

调用格式:

<!--springmvc环境-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>

内置属性

作用:使用Maven内置属性,快速配置

例如,父工程和子工程的版本号一样,可以直接使用父工程的版本内置属性${version}:

<!--添加自己工程的依赖-->
<dependency>
<groupId>com.zx</groupId>
<artifactId>ssm_service</artifactId>
<version>${version}</version>
</dependency>

Setting属性

作用:使用Maven配置文件setting.xml中的标签属性,用于动态配置

调用格式:${settings.localRepository}

Java系统属性

作用:读取Java系统属性

调用格式:${user.home}

系统属性查询方式:mvn help:system

环境变量属性

作用:使用Maven配置文件setting.xml中的标签属性,用于动态配置

调用格式:${env.JAVA_HOME}

环境变量查询方式:mvn help:system

版本管理

1.工程版本

SNAPSHOT快照版本

  • 项目开发过程中,为方便团队成员合作,解决模块间相互依赖和时时更新的问题,开发者对每个模块进行构建的时候,输出的临时性版本叫快照版本(测试阶段版本)
  • 快照版本会随着开发的进展不断更新

RELEASE发布版本

  • 项目开发到进入阶段里程碑后,向团队外部发布较为稳定的版本,这种版本所对应的构件文件是稳定的,即便进行功能的后续开发,也不会改变当前发布版本内容,这种版本称为发布版本

2.工程版本号约定

约定规范:

  • <主版本>.<次版本>.<增量版本>.<里程碑版本>

  • 主版本∶表示项目重大架构的变更,如∶spring5相较于spring4的迭代

  • 次版本∶表示有较大的功能增加和变化,或者全面系统地修复漏洞

  • 增量版本∶表示有重大漏洞的修复

  • 里程碑版本∶表明一个版本的里程碑(版本内部)。这样的版本同下一个正式版本相比,相对来说不是很稳定,有待更多的测试

范例:

  • 5.1.9.RELEASE

资源配置

1.资源配置多文件维护

image-20220122184324524-3

2.配置文件引用pom属性

作用:在任意配置文件中加载pom文件中定义的属性

调用格式:${jdbc.url}

开启配置文件加载pom属性

<!--配置资源文件对应的信息-->
<resources>
<resource>
<!--设定配置文件对应的位置目录,支持使用属性动态设定路径-->
<directory>${project.basedir}/src/main/resources</directory>
<!--开启对配置文件的资源加载过滤-->
<filtering>true</filtering>
</resource>
</resources>

多环境开发配置

<!--创建多环境-->
<profiles>
<!--定义具体的环境:生产环境-->
<profile>
<!--定义环境对应的唯一名称-->
<id>pro_env</id>
<!--定义环境中使用的属性值-->
<properties>
<jdbc.url>jdbc:mysql://127.0.0.1:3306/ssm_db?useSSL=false</jdbc.url>
</properties>
<!--设置默认启动-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!--定义具体的环境:开发环境-->
<profile>
<!--定义环境对应的唯一名称-->
<id>dev_env</id>
...
</profile>
</profiles>

加载指定环境:mvn 指令 -P 环境定义id

mvn install -P pro_env

跳过测试

跳过测试环节的应用场景:

  • 整体模块功能未开发
  • 模块中某个功能未开发完毕
  • 单个功能更新调试导致其他功能失败
  • 快速打包(因为测试需要耗费时间)

2.使用命令跳过测试:

mvn 指令 -D skipTests

注意:执行的指令生命周期必须包含测试环节

3.使用界面操作跳过测试

image-20220809125950108

4.使用配置跳过测试

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<!--设置跳过测试-->
<skipTests>true</skiplests>
<!--包含指定的测试用例-->
<includes>
<include>**/User*Test.java</include>
</includes>
<!--排除指定的测试用例-->
<excludes>
<exclude>**/User*TestCase.java</exclude>
</excludes>
</configuration>
</plugin>

私服

Nexus安装、启动与配置

启动服务器(命令行启动):nexus.exe /run nexus

访问服务器(默认端口8081):http://localhost:8081

修改基础配置信息:安装路径下etc目录中nexus-default.properties文件保存有nexus基础配置信息,例如默认访问端口

修改服务器运行配置信息:安装路径下bin目录中nexus.vmoptions文件保存有nexus服务器启动对应的配置信息,例如默占用内存空间

私服-资源获取

image-20220122212618331-2

私服仓库分类

宿主仓库hosted

  • 保存无法从中央仓库获取的资源:自主研发、第三方非开源项目

代理仓库proxy

  • 代理远程仓库,通过nexus访问其他公共仓库,例如中央仓库

仓库组group

  • 将若干个仓库组成一个群组,简化配置
  • 仓库组不能保存资源,属于设计型仓库

私服-资源上传

提供信息:保存位置(宿主仓库)、资源文件、对应坐标

私服-idea环境中资源上传与下载

image-20220809131930755

访问私服配置(本地仓库访问私服)

配置本地仓库访问私服的权限(setting.xml)

<servers>
<server>
<!--宿主仓库id-->
<id>heima-release</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>heima-snapshot</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>

配置本地仓库资源来源(setting.xml)

<!--中央仓库的资源从阿里云下载-->
<mirror>
<id>nexus-aliyun</id>
<name>nexus-aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>

<!--其他的从私服下载-->
<mirror>
<id>nexus-heima</id>
<!--url为maven-public仓库组的url-->
<url>http://localhost:8081/repository/maven-public</url>
<mirrorOf>*</mirrorOf>
</mirror>

访问私服配置(项目工程访问私服)

配置当前项目访问私服上传资源的保存位置(pom.xml)

<!--发布配置管理-->
<distributionManagement>
<repository>
<!--发布到发行版的仓库,注意这里的id必须和setting.xml配置的id相同-->
<id>heima-release</id>
<!--发行版仓库的url-->
<url>http://localhost:8081/repository/heima-release/</url>
</repository>
<snapshotRepository>
<!--发布到快照版的仓库-->
<id>heima-snapshot</id>
<!--快照版仓库的url-->
<url>http://localhost:8081/repository/heima-snapshot/</url>
</snapshotRepository>
</distributionManagement>

发布资源到私服命令:mvn deploy