如何为本地 Maven 安装维护两个 Maven 配置文件?

How to maintain two maven profiles for local maven installation?

我在办公室(我目前工作的软件公司)使用本地计算机进行开发工作。他们有不同的 Maven 设置。它指向他们自己的 Maven 存储库。 但是,为了我自己在家的工作,我想访问默认的 Maven 设置。

那么,我该如何实现呢?是否可以通过为办公室和我自己的作品维护两个单独的 maven 配置文件来做到这一点?

公司特定配置定义了一些服务器和存储库。当我在家工作而不维护单独的 settings.xml 文件时,我应该如何配置 settings.xml 文件以连接默认的 maven 存储库?

是的,您可以为两者使用一个 ~/.m2/settings.xml 文件。下面是我正在使用的示例。服务器在配置文件之外,因为它们仅在通过 ID 引用时使用。

在我的 IDE 中,我为公司项目启用了 comp 配置文件,为 atlassian SDK 项目启用了 atlassian 配置文件,为其他项目启用了 none 配置文件。在 IntelliJ IDEA you can do this via sidebar, while in Eclipse you have to do this 中。在命令行中,您必须通过 -P 手动激活它们。但是,您可以尝试基于 属性 的自动配置文件激活。

<?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">
    <servers>
        <server>
            <id>comp-releases</id>
            <username>me</username>
            <password>secret</password>
        </server>
        <server>
            <id>comp-snapshots</id>
            <username>me</username>
            <password>secret</password>
        </server>
    </servers>

    <profiles>
        <profile>
            <id>comp</id>
            <repositories>
                <repository>
                    <id>comp-nexus</id>
                    <name>Nexus Public</name>
                    <url>https://www.example.com/nexus/content/groups/public/</url>
                </repository>
            </repositories>
        </profile>
        <profile>
            <id>atlassian</id>
            <repositories>
                <repository>
                    <id>atlassian-public</id>
                    <url>https://maven.atlassian.com/repository/public</url>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>atlassian-public</id>
                    <url>https://maven.atlassian.com/repository/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <updatePolicy>never</updatePolicy>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
</settings>