maven 配置
公司因为jar包管理混乱(本地缺这个缺那个的),因此建了一个私库。但是仍然很混乱,因为maven配置问题,有些组拉不下来,有些组更新完jar包版本后并没有上传至私库,找别的同事要的setting文件,要不不生效,要不乱得很,网上查的也是,多数都是乱配的(巧合式编程),只好自己看官方文档来配置了。
如何上传至远程仓库
单一项目(需配置pom.xml与setting.xml)
段落:How do I deploy my jar in my remote repository?
pom.xml:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
...
<!-- 远程仓库配置 -->
<distributionManagement>
<repository>
<id>mycompany-repository</id>
<name>MyCompany Repository</name>
<url>scp://repository.mycompany.com/repository/maven2</url>
</repository>
</distributionManagement>
</project>
setting.xml
<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 https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<!-- 身份验证 -->
<servers>
<server>
<id>mycompany-repository</id>
<username>jvanzyl</username>
<!-- Default value is ~/.ssh/id_dsa -->
<privateKey>/path/to/identity</privateKey> (default is ~/.ssh/id_dsa)
<passphrase>my_key_passphrase</passphrase>
</server>
</servers>
...
</settings>
全局(显式激活)
仅配置setting.xml
<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 https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<!-- 身份验证 -->
<servers>
<server>
<id>mycompany-repository</id>
<username>jvanzyl</username>
<!-- Default value is ~/.ssh/id_dsa -->
<privateKey>/path/to/identity</privateKey> (default is ~/.ssh/id_dsa)
<passphrase>my_key_passphrase</passphrase>
</server>
</servers>
<!-- 配置id与activeProfile需一致 -->
<profiles>
<profile>
<id>yra</id>
<repository>
<repositories>
<repository>
<releases>
<enabled/>
<updatePolicy/>
<checksumPolicy/>
</releases>
<snapshots>
<enabled/>
<updatePolicy/>
<checksumPolicy/>
</snapshots>
<id/>
<name/>
<url/>
<layout/>
</repository>
</repositories>
</repository>
</profile>
</profiles>
<!-- 激活 -->
<activeProfiles>
<activeProfile>yra</activeProfile>
</activeProfiles>
...
</settings>
profile (可实现: 单一项目配置、单一用户配置、全局配置)
setting 配置项 参考: https://maven.apache.org/ref/3.9.6/maven-settings/settings.html
pom 配置项 参考: https://maven.apache.org/ref/3.9.6/maven-model/maven.html
如何使用profile
参考: https://maven.apache.org/guides/introduction/introduction-to-profiles.html
激活方式:
- 显式
- 隐式
- JDK
- OS
- 环境
- 文件(是否存在)