Maven
南大源采用了阿里云(central + jcenter + gradle-plugin),腾讯云(central+jcenter+google)和 maven central 官方的混合形式。
maven 配置指南
全局配置
配置当前登录用户使用南大源,如果未修改过 maven 的默认配置文件位置,请如下操作:
-
linux 用户在终端中输入以下命令:
mkdir ~/.m2 vim ~/.m2/settings.xml -
windows 用户在 powershell (或者pwsh中) 输入以下命令:
mkdir ~/.m2 cd ~/.m2 notepad settings.xml
如果打开的文件为空,粘贴以下内容:
<?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">
<mirrors>
<mirror>
<id>nju_mirror</id>
<mirrorOf>*</mirrorOf>
<url>https://repo.nju.edu.cn/repository/maven-public/maven/</url>
</mirror>
</mirrors>
</settings>
如果已经有内容,则在 mirrors 节点加入子节点 (对于 mirrorOf 值相同的节点,只有首个子节点生效):
<mirror>
<id>nju_mirror</id>
<mirrorOf>*</mirrorOf>
<url>https://repo.nju.edu.cn/repository/maven-public/maven/</url>
</mirror>
保存退出即可使用。
项目配置
如果只在某个项目中使用,则在项目的 pom.xml 中配置:
<project>
......[其他配置]
<repositories>
<repository>
<id>nju</id>
<url>https://repo.nju.edu.cn/repository/maven-public/maven/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
maven 私服
南京大学 maven 仓库同时提供 jar 包托管服务,本校师生可以将自己编写的 jar 发布到仓库中让其他人使用。此仓库文件不会同步到其他镜像源。
从仓库获取文件
将上面提到的仓库地址改为 https://repo.nju.edu.cn/repository/maven-nju/ 即可。
使用此仓库请注意:
向仓库提交文件
在 ~/.m2/settings.xml 中,为 settings 节点添加以下子节点:
<servers>
<server>
<id>nju-server</id>
<username>学工号</username>
<password>统一身份认证密码</password>
</server>
</servers>
在项目的 pom.xml 中,为 project 节点添加以下子节点:
<distributionManagement>
<repository>
<id>nju-server</id>
<name>Releases</name>
<url>http://repo.nju.edu.cn/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nju-server</id>
<name>Snapshot</name>
<url>http://repo.nju.edu.cn/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement>
在项目根目录下运行 mvn deploy 即可发布,若版本号中以 -SNAPSHOT 结尾,会发布到 maven-snapshots, 否则会发布到 maven-releases。
注意
com.example