【问题标题】:How to maintain two maven profiles for local maven installation?如何为本地 maven 安装维护两个 maven 配置文件?
【发布时间】:2016-07-16 16:21:43
【问题描述】:

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

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

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

【问题讨论】:

  • 你用的是什么IDE?
  • @AntonKoscejev 我正在使用 Eclipse。但即使我使用命令行我也有问题。
  • 最好是为 .m2/settings.xml 创建一个本地 git repo 并更改 Git 中的分支以便在家和公司工作。

标签: maven maven-3


【解决方案1】:

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

在我的 IDE 中,我为公司项目启用了 comp 配置文件,为 atlassian SDK 项目启用了 atlassian 配置文件,而其他项目都没有。在 IntelliJ IDEA you can do this via sidebar 中,而在 Eclipse 中你必须这样做 via Project Properties。您必须从命令行通过-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>

【讨论】:

    猜你喜欢
    • 2011-06-07
    • 1970-01-01
    • 2016-12-12
    • 1970-01-01
    • 2014-12-03
    • 1970-01-01
    • 2023-03-16
    • 2014-06-18
    • 1970-01-01
    相关资源
    最近更新 更多