02 本地maven配置

本地maven配置

找到项目使用的settings.xml文件

增加maven下载和上传artifact的配置

配置server,profile,activeProfile

<?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>ole12138-maven-public</id>
          <username>账号</username>
          <password>密码</password>
        </server>
    </servers>

    <profiles>
        <profile>
            <id>repo-ole12138-maven-public</id>
            <!-- 
            这里的 repositories 如果不配置的话,默认会有一个 Maven 中央仓库的配置,
            同样 pluginRepositories 中如果没有配置的话,默认也是有一个 Maven 中央仓库的配置。
            所以如果只配置了私服的 repository 情况下,就会先去私服中下载,私服中下载不到时再去追加上来的 Maven 中央仓库中下载
            -->
            <!-- 配置的顺序决定了下载 jar 包的顺序 -->
            <repositories>
                <repository>
                     <id>ole12138-maven-public</id>
                    <url>https://nexus.ole12138.cn/repository/maven-public/</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </repository>
            </repositories>
            
            <pluginRepositories>
                <pluginRepository>          
                    <id>ole12138-maven-public</id>
                     <url>https://nexus.ole12138.cn/repository/maven-public/</url>
                     <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </pluginRepository>
            </pluginRepositories>
            
            <!-- 默认上传artifact的仓库位置 -->
            <!-- how-to-specify-mavens-distributionmanagement-organisation-wide -->
            <!-- https://stackoverflow.com/questions/3298135/how-to-specify-mavens-distributionmanagement-organisation-wide -->
            <properties>
                <altSnapshotDeploymentRepository>ole12138-maven-public::default::https://nexus.ole12138.cn/repository/maven-snapshots/</altSnapshotDeploymentRepository>
                <altReleaseDeploymentRepository>ole12138-maven-public::default::https://nexus.ole12138.cn/repository/maven-releases/</altReleaseDeploymentRepository>
            </properties>
        </profile>
    </profiles>

    <activeProfiles>
        <!-- 激活环境配置 ,使上面的配置生效 --> 
        <activeProfile>repo-ole12138-maven-public</activeProfile>
    </activeProfiles>

</settings>

看到有些项目里,配置了nexus-public, nexus-thirdparty这两个repository。统一设置下mirror

<?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>nexus-public-mirror</id>
          <username>账号</username>
          <password>密码</password>
        </server>
        <server>
          <id>nexus-thirdparty-mirror</id>
          <username>账号</username>
          <password>密码</password>
        </server>
    </servers>


    <mirrors>

        <!-- 覆盖默认的maven-default-http-blocker,允许http -->
        <!--<mirror>
               <id>maven-default-http-blocker</id>
               <mirrorOf>dummy</mirrorOf>
               <name>Dummy mirror to override default blocking mirror that blocks http</name>
               <url>http://0.0.0.0/</url>
         </mirror>-->

        <mirror>
            <id>nexus-public-mirror</id>
            <name>public Repository</name>
            <url>https://nexus.ole12138.cn/repository/maven-public/</url>
            <mirrorOf>nexus-public</mirrorOf>
        </mirror>
        <mirror>
            <id>nexus-thirdparty-mirror</id>
            <name>Third Party Repository</name>
            <url>https://nexus.ole12138.cn/repository/thirdparty/</url>
            <mirrorOf>nexus-thirdparty</mirrorOf>
        </mirror>
    </mirrors>



</settings>

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注