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

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

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

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

    
<id>nexusid> <repositories> <repository> <id>maven-releasesid> <url>http://192.168.0.54:8899/ajco/repository/maven-releases/url> <releases> <enabled>trueenabled> <updatePolicy>alwaysupdatePolicy> releases> <snapshots> <enabled>trueenabled> <updatePolicy>alwaysupdatePolicy> snapshots> repository> <repository> <id>maven-snapshotsid> <url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/url> <releases> <enabled>trueenabled> <updatePolicy>alwaysupdatePolicy> releases> <snapshots> <enabled>trueenabled> <updatePolicy>alwaysupdatePolicy> snapshots> repository> repositories> <pluginRepositories> <pluginRepository> <id>maven-releasesid> <url>http://192.168.0.54:8899/ajco/repository/maven-releases/url> <releases> <enabled>trueenabled> <updatePolicy>alwaysupdatePolicy> releases> <snapshots> <enabled>trueenabled> <updatePolicy>alwaysupdatePolicy> snapshots> pluginRepository> <pluginRepository> <id>maven-snapshotsid> <url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/url> <releases> <enabled>trueenabled> <updatePolicy>alwaysupdatePolicy> releases> <snapshots> <enabled>trueenabled> <updatePolicy>alwaysupdatePolicy> snapshots> pluginRepository> pluginRepositories> profile> <profile> <id>aliyunid> <repositories> <repository> <id>centralid> <url>http://maven.aliyun.com/nexus/content/groups/public/url> repository> repositories> <pluginRepositories> <pluginRepository> <id>centralid> <url>http://maven.aliyun.com/nexus/content/groups/public/url> pluginRepository> pluginRepositories> profile>

 

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

    <activeProfile>nexusactiveProfile>
    <activeProfile>aliyunactiveProfile>

 

    说明:

        1.这里aliyun仓库的id设置为central,则会覆盖maven里默认的远程仓库。

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

      <mirror>
          <id>alimavenid>
          <mirrorOf>centralmirrorOf>
          <name>aliyun mavenname>
          <url>http://maven.aliyun.com/nexus/content/repositories/central/url>
      mirror>

 

配置maven deploy:

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

    <server>
        <id>deploymentRepoid>
        <username>repouserusername>
        <password>repopwdpassword>
    server>

 

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

    <distributionManagement>
        <repository>
            <id>deploymentRepoid>
            <url>http://192.168.0.54:8899/ajco/repository/maven-releases/url>
        repository>
        <snapshotRepository>
            <id>deploymentRepoid>
            <url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/url>
        snapshotRepository>
    distributionManagement>

 

你可能感兴趣的:(maven多仓库配置 公司仓库和阿里仓库)