maven多仓库配置 公司仓库和阿里仓库

针对公司内网私服仓库,私服仓库不能访问外网,此时无法在私服仓库代理阿里的maven仓库。我们的maven就需要配置多个仓库:

maven目录下的conf/settings.xml配置文件:

一、在profiles标签内新建profile,配置一个公司的仓库和阿里的仓库;

    <profile>
<id>nexus</id> <repositories>
<!-- 私服发布仓库,即私服正式jar仓库 --> <repository> <id>maven-releases</id> <url>http://192.168.0.54:8899/ajco/repository/maven-releases/</url> </repository>
<!-- 私服快照仓库,即私服临时jar仓库 --> <repository> <id>maven-snapshots</id> <url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/</url> </repository> </repositories>
<!-- 私服插件仓库,一般插件都是从外网仓库下载,可以不用配置 -->
<pluginRepositories> <pluginRepository> <id>maven-releases</id> <url>http://192.168.0.54:8899/ajco/repository/maven-releases/</url> </pluginRepository> <pluginRepository> <id>maven-snapshots</id> <url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/</url> </pluginRepository> </pluginRepositories> </profile> <profile>
<id>aliyun</id> <repositories>
<!-- 外网仓库,用国内阿里仓库 -->
<repository> <id>central</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </pluginRepository> </pluginRepositories> </profile>

 

二、在activeProfiles标签内配置activeProfile,激活上面的仓库,activeProfile里的值对应上面profile里的id值

    <activeProfile>nexus</activeProfile>
    <activeProfile>aliyun</activeProfile>

 

    说明:

        1.maven有个默认的外网中央仓库,id是central。在mirrors标签内配置一个mirrorOf=central的镜像,则使用这个镜像地址替换这个外网中央仓库;

        2.profiles标签里的aliyun的仓库也可以不用配置,直接在mirrors标签内配置一个镜像仓库,mirrors镜像仓库mirrorOf的值设置为central,则也可以实现覆盖默认的仓库

    <mirror>
        <id>alimaven</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>

 

配置maven deploy:

    如果需要将本地项目deploy打包上传到私服仓库,则需要配置如下信息:

一、在settings.xml的servers标签内新建server标签,定义一个登录私服的账号密码配置;

    <server>
        <id>deploymentRepo</id>
        <username>repouser</username>
        <password>repopwd</password>
    </server>

 

二、项目的pom.xml文件加入如下配置,id对应上面的server里的id,表示deploy时上传到下面的仓库,用上面的账号密码;

    说明:本地项目version如果以-snapshots结尾,maven则自动选择上传到snapshotRepository仓库,即配置的快照仓库,否则上传到发布仓库。

 

    <distributionManagement>
        <repository>
            <id>deploymentRepo</id>
            <url>http://192.168.0.54:8899/ajco/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>deploymentRepo</id>
            <url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
posted @ 2019-12-04 13:35  cruder  阅读(4293)  评论(0编辑  收藏  举报