如何解决Maven: Failed to read artifact descriptor

简介

本文总结了在Maven多模块项目下,一模块引用其它模块时,如何解决“Failed to read artifact descriptor”问题。

多子模块项目创建

这两天尝试创建多模块项目,参考了《Maven权威指南》第6章的内容,其中父模块的POM配置如下:


	4.0.0
	org.sonatype.mavenbook.ch06
	simple-parent
	pom
	1.0-SNAPSHOT
	simple-parent
	http://maven.apache.org
	
	
	   simple-weather
	   simple-webapp
	
	
		
			junit
			junit
			4.12
			test
		
	
	
	
	   
	   
	       
	           
	               org.apache.maven.plugins
	               maven-compiler-plugin
	               
	                   1.8
	                   1.8
	               
	           
	           
	       
	   
	

simple-weather子模块的POM配置:


	4.0.0

	
		org.sonatype.mavenbook.ch06
		simple-parent
		1.0-SNAPSHOT
	

	simple-weather
	jar
	simple-weather
	http://maven.apache.org

	
		
			log4j
			log4j
			1.2.14
		

		
			dom4j
			dom4j
			1.6.1
		

		
			jaxen
			jaxen
			1.1.1
		

		
			velocity
			velocity
			1.5
		

		
			org.apache.commons
			commons-io
			1.3.2
			test
		
	

	
		simple-weather
		
			
				org.apache.maven.plugins
				maven-surefire-plugin
				
					
					true
				
			

			
				maven-assembly-plugin
				
					jar-with-dependencies
				
			
		
	
simple-webapp子模块:


	4.0.0

	
		org.sonatype.mavenbook.ch06
		simple-parent
		1.0-SNAPSHOT
	

	simple-webapp
	war
	simple-webapp Maven Webapp
	http://maven.apache.org
	
		
			org.apache.geronimo.specs
			geronimo-servlet_3.0_spec
			1.0
			provided
		

		
			org.sonatype.mavenbook.ch06
			simple-weather
			${project.version}
		
	
	
		simple-webapp
		
			
				org.mortbay.jetty
				maven-jetty-plugin
			
		
	

编译、安装

首先针对simple-weather子模块项目进行编译和安装:进入simple-weather子项目目录

mvn compile
mvn install
进入simple-webapp子模块项目目录下,通过mvn compile编译时,出现下面的错误

[ERROR] Failed to execute goal on project simple-webapp: Could not resolve dependencies for project 
org.sonatype.mavenbook.ch06:simple-webapp:war:1.0-SNAPSHOT: Failed to collect dependencies at 
org.sonatype.mavenbook.ch06:simple-weather:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for 
org.sonatype.mavenbook.ch06:simple-weather:jar:1.0-SNAPSHOT: Could not find artifact 
org.sonatype.mavenbook.ch06:simple-parent:pom:1.0-SNAPSHOT -> [Help 1]
针对这个问题,首先是检查了POM文件配置,没有什么异常信息。查看本地.m2/repository的安装情况,也都正常。再次通过mvn -U clean install为simple-weather子模块进行清空后安装,问题依然存在。最终在stackoverflow上发现了类似的问题,发现有人给出的下面的解决方案,最终解决了我的问题:

This problem can occur if you have some child projects that refer to a parent pom and you have not installed from the parent pom directory (run mvn install from the parent directory). One of the child projects may depend on a sibling project and when it goes to read the pom of the sibling, it will fail with the error mentioned in the question unless you have installed from the parent pom directory at least once.
大致翻译一下:如果你有子项目引用了父项目的POM,但没有在父项目POM目录下执行安装操作,这个问题就会出现。针对子模块依赖兄弟子模块的情况,需要在父项目POM目录下至少执行一次安装。

参考资料

1. Maven: Failed to read artifact descriptor

你可能感兴趣的:(Maven)