笔记:Maven 仓库和插件配置本机私服

通过配置POM中的配置仓库和插件仓库,只在当前项目生效,而实际应用中,我们希望通过一次配置就能让本机所有的Maven项目都使用自己的Maven私服,这个时候我们需要配置 settings.xml文件,该文件中的配置对所有本机的Maven项目有效,但是 settings.xml 并不支持直接配置 repositories pluginRepositories,Maven提供了 profile 机制,能让用户将仓库配置放到 settings.xml 中的 profile 中,配置说明如下:

<profiles>

    <profile>

        <!-- profile 的唯一ID -->

        <id>innerRepository</id>

        <!-- 仓库配置 -->

        <repositories>

         <repository>

<!-- 配置为 central 会覆盖超级POM中央仓库的配置 -->

            <id>central</id>

            <name>inner Repository</name>

            <url>http://localhost:8081/nexus/content/groups/public/</url>

            <layout>default</layout>

            <releases>

                <enabled>true</enabled>

            </releases>

            <snapshots>

                <enabled>false</enabled>

            </snapshots>

         </repository>

        </repositories>

        <!-- 插件仓库配置-->

        <pluginRepositories>

            <pluginRepository>

<!-- 配置为 central 会覆盖超级POM中央仓库的配置 -->

                <id>central</id>

                <name>public Group</name>

                <url>http://localhost:8081/nexus/content/groups/public/</url>

                <layout>default</layout>

                <releases>

                    <enabled>true</enabled>

                </releases>

                <snapshots>

                    <enabled>false</enabled>

                </snapshots>

            </pluginRepository>

        </pluginRepositories>

    </profile>

</profiles>

然后在 activeProfiles 中启用 profile,配置如下:

<activeProfiles>

    <!-- 激活的 Profile 唯一ID -->

        <activeProfile>innerRepository</activeProfile>

</activeProfiles>

原文地址:https://www.cnblogs.com/li3807/p/6416214.html