eclipse创建maven工程问题总结

一、在eclipse导入maven工程或创建maven工程时,会出现以下错误:

Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:3.1 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be 
 reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:3.1 
 from/to central (https://repo.maven.apache.org/maven2): sun.security.validator.ValidatorException: PKIX path building failed: 

 sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target


Multiple annotations found at this line:
- CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to read 
artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:3.1: ArtifactResolutionException: Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:
3.1 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are 
forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:3.1 from/to central (https://repo.maven.apache.org/maven2): 
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (execution: default-testCompile, phase: test-
compile)
- CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to read 
artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:3.1: ArtifactResolutionException: Could not transfer artifact org.apache.maven.plugins:maven-compiler-
plugin:pom:3.1 from/to central (https://repo.maven.apache.org/maven2): sun.security.validator.ValidatorException: PKIX path building failed: 
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (execution: default-compile, phase: compile)


以上基本上是由于网络问题导致连接不到中央库引起。

解决办法1:在pom.xml增加如下配置,替换默认的编译配置

<build>
<plugins>  
       <plugin>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>3.3</version>
       <executions>
         <execution>
           <id>default-compile</id>
           <phase>compile</phase>
           <goals>
             <goal>compile</goal>
           </goals>
           <configuration>
             <source>1.8</source>
             <target>1.8</target>
             <encoding>UTF-8</encoding>
           </configuration>
         </execution>
         <execution>
           <id>default-testCompile</id>
           <phase>test-compile</phase>
           <goals>
             <goal>testCompile</goal>
           </goals>
           <configuration>
             <source>1.8</source>
             <target>1.8</target>
             <encoding>UTF-8</encoding>
           </configuration>
         </execution>
       </executions>
       <configuration>
         <source>1.8</source>
         <target>1.8</target>
         <encoding>UTF-8</encoding>
       </configuration>
     </plugin>
   </plugins>  

</build>

解决方法2:替换仓库位置

修改maven配置文件setting.xml,使用阿里云的镜像

扫描二维码关注公众号,回复: 1801890 查看本文章

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

修改以上配置后,点击工程右键--Maven--Update Project刷新工程。

猜你喜欢

转载自blog.csdn.net/long2010110/article/details/80814062