开发者

解读maven配置阿里云镜像问题

目录
  • maven配置阿里云镜像
  • maven配置阿里云镜像仓库不生效
    • 问题
    • 解决方法
    • 原因

maven配置阿里云镜像

打开maven配置文件,找到标签,添加如下:

<mirrors>

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

</mirrors>

设置全局的jdk,在配置文件配置如下:

<profile> 
  <id>jdk18</id> 
  <activation> 
    <activeByDefault>true</activeByDefault> 
    <jdk>1.8</jdk> 
  </activation> 
  <properties> 
    <maven.compiler.source>1.8</maven.compiler.source> 
    &pythonlt;maven.compiler.target>1.8</maven.compiler.target> 
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> 
  </properties> 
</profile> 

设置局部的jdk,在项目的pom,xandroidml文件中添加如下build元素

<build> 
  <plugins> 
    <plugin> 
      <groupId&gandroidt;org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
      </configuraphption> 
    </plugin> 
  </plugins> 
</build>

maven配置阿里云镜像仓库不生效

问题

在{MAVEN_HOME}/conf/settings.XML中添加镜像配置:

 <mirrors>
  <mirror>
    <id>aliyjavascriptunmaven</id>
    <mirrorOf>*</mirrorOf>
    <name>开发者_开发培训;阿里云公共仓库</name>
    <url>https://maven.aliyun.com/repository/public</url>
  </mirror>
 </mirrors>

但是项目更新时仍然会从http://repo.maven.apache.org/maven2下载依赖。

解决方法

在项目的pom.xml中添加如下配置

 <repositories>
  <repository>
   <id>central</id>
   <url>https://maven.aliyun.com/repository/public</url>
  </repository>
 </repositories>
 <pluginRepositories>
  <pluginRepository>
   <id>central</id>
   <url>https://maven.aliyun.com/repository/public</url>
  </pluginRepository>
 </pluginRepositories>

原因

项目的pom会继承自super pom,在super pom中指定了从仓库的地址:

<repositories>
  <repository>
   <id>central</id>
   <name>Central Repository</name>
   <url>http://repo.maven.apache.org/maven2</url>
   <layout>default</layout>
   <snapshots>
    <enabled>false</enabled>
   </snapshots>
  </repository>
 </repositories>

 <pluginRepositories>
  <pluginRepository>
   <id>central</id>
   <name>Central Repository</name>
   <url>http://repo.maven.apache.org/maven2</url>
   <layout>default</layout>
   <snapshots>
    <enabled>false</enabled>
   </snapshots>
   <releases>
    <updatePolicy>never</updatePolicy>
   </releases>
  </pluginRepository>
 </pluginRepositories>

因此需要在项目中覆盖这一配置。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新开发

开发排行榜