最近被IDEA maven 往死里搞了一次,一旦打包,就会各种找不到jar包,而本地仓库这些jar包都有。各种修改配置文件,修改仓库路径,最终通过替换maven setting 文件来实现逆转。
IDEA 在maven setting 文件被破坏之后,会使用自己的默认配置,然后就会出现各种问题,在此留个纪念,保留一个可用的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
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
-->
<localRepository>C:\workProject\.m2</localRepository>
<!-- 配置镜像 -->
<mirrors>
<mirror>
<!-- 此镜像一般用来作为公司内部开发的版本快照,作为public-snapshots仓库的镜像地址 -->
<!-- 镜像的id,id用来区分不同的mirror元素。 -->
<id>nexus-public-snapshots</id>
<!-- 被镜像的服务器的id。例如,如果我们要设置了一个Maven中央仓库(http://repo1.maven.org/maven2)的镜像,
就需要将该元素设置成central。这必须和中央仓库的id “central”完全一致。 -->
<mirrorOf>public-snapshots</mirrorOf>
<!-- 该镜像的URL。 -->
<url>http://repos.d.xxx.com/nexus/content/groups/public-snapshots</url>
</mirror>
<!-- MSP仓库 -->
<!--<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.92.5:8081/nexus/content/groups/public/</url>
</mirror>
-->
<!-- Spring仓库地址 -->
<!--mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>https://repo.spring.io/libs-milestone</url>
</mirror-->
<!-- 阿里云公网仓库 -->
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
<!-- settings.xml中的profile元素是pom.xml中profile元素的裁剪版本。它包含了activation, repositories, pluginRepositories 和 properties元素。
这里的profile元素只包含这四个子元素是因为这里只关心构建系统这个整体(这正是settings.xml文件的角色定位),而非单独的项目对象模型设置。
如果一个settings中的profile被激活,它的值会覆盖任何其它定义在POM中或者profile.xml中的带有相同id的profile。 -->
<profiles>
<profile>
<id>development</id>
<!-- 仓库。仓库是Maven用来填充构建系统本地仓库所使用的一组远程项目。而Maven是从本地仓库中使用其插件和依赖。
不同的远程仓库可能含有不同的项目,而在某个激活的profile下,可能定义了一些仓库来搜索需要的发布版或快照版构件。有了Nexus,这些应该交由Nexus完成 -->
<repositories>
<repository>
<id>central</id>
<!-- 虚拟的URL形式,指向镜像的URL,因为所有的镜像都是用的是nexus,这里的central实际上指向的是http://repos.d.xxx.com/nexus/content/groups/public -->
<url>http://central</url>
<!-- 表示可以从这个仓库下载releases版本的构件-->
<releases><enabled>true</enabled></releases>
<!-- 表示可以从这个仓库下载snapshot版本的构件 -->
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<!-- 插件仓库。仓库是两种主要构件的家。第一种构件被用作其它构件的依赖。这是中央仓库中存储大部分构件类型。
另外一种构件类型是插件。Maven插件是一种特殊类型的构件。由于这个原因,插件仓库独立于其它仓库。
pluginRepositories元素的结构和repositories元素的结构类似。每个pluginRepository元素指定一个Maven可以用来寻找新插件的远程地址。 -->
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--this profile will allow snapshots to be searched when activated-->
<id>public-snapshots</id>
<repositories>
<repository>
<id>public-snapshots</id>
<!-- 虚拟的URL形式,指向镜像的URL,这里指向的是http://repos.d.xxx.com/nexus/content/groups/public-snapshots -->
<url>http://public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public-snapshots</id>
<url>http://public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- 激活的Profile。activation元素并不是激活profile的唯一方式。settings.xml文件中的activeProfile元素可以包含profile的id,
任何在activeProfile中定义的profile id,不论环境设置如何,其对应的profile都会被激活。如果没有匹配的profile,则什么都不会发生。
profile也可以通过在命令行,使用-P标记和逗号分隔的列表来显式的激活(如,-P test)。
要了解在某个特定的构建中哪些profile会激活,可以使用maven-help-plugin(mvn help:active-profiles)。 -->
<activeProfiles>
<!-- 没有显示激活public-snapshots -->
<activeProfile>development</activeProfile>
</activeProfiles>
<!-- 发布的服务器和密码,暂时未限制权限 -->
<server>
<id>Release</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>Snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</settings>