maven依赖--dependency命令

maven 依赖

要分析的pom文件:


	4.0.0
	uk.ac.liverpool
	JTViewer
	0.7.1
	The JT format parser and renderer
	

		
			Fabio Corubolo
			[email protected]
		
		
			Jerome Fuselier
			[email protected]
		

	

	A pure Java library to decode the JT(TM) file format from Siemens PLM (TM).
See http://www.jtopen.com/ for samples and the file format specification. See licensing for the specific JT specification license data structures license. The library is produced independently and has no affiliation to Siemens PLM (TM).
This library curerntly parses JT files including faceted data, the Logocal Scene Graph and other the necessary information, and renders it using the JReality toolkit.
	http://code.google.com/p/jt-java/
	2010
	
		
			
			
				org.apache.maven.plugins
				maven-compiler-plugin
				
					
					1.5
					1.5
				
			

			
			
				org.apache.maven.plugins
				maven-jar-plugin

				
					
						
							
							true
							
							uk.ac.liv.jt.viewer.JTViewer
						
					
				
			

			
			
				maven-assembly-plugin
				
					
						
						assemble
						package
						
							single
						
						
							
								
								src/main/assembly/jtv.xml
							
						
					
				
				
					JTViewer
				
			
		

	

	
		
			google.code.fab4project
			google.code.fab4project
			
			https://github.com/jasonknight/jreality/tree/master/lib
		

	

	

		
			jreality
			jReality
			1.0
			system
			D:/lib/jReality.jar
		

		
			jreality
			jrworkspace
			1.0
			system
			D:/lib/jrworkspace.jar
		

		
			jreality
			jterm
			1.0
			system
			D:/lib/jterm.jar
		

		
			jreality
			smrj.jar
			1.0
			system
			D:/lib/smrj.jar
		

		
		
			jreality
			sunflow.jar
			1.0
			system
			D:/lib/sunflow.jar
		

		
		
			jreality
			colorpicker
			1.0
			system
			D:/lib/colorpicker.jar
		

		
			jreality
			beans
			1.0
			system
			D:/lib/beans.jar
		

		
			com.lowagie
			itext
			2.1.3
			jar
			compile
			
				
					bcmail-jdk14
					bouncycastle
				
				
					bcprov-jdk14
					bouncycastle
				
			
		

		
			com.thoughtworks.xstream
			xstream
			1.3.1
			jar
			compile
		

		
			org.beanshell
			bsh
			2.0b4
			jar
			compile
		

		
			org.codehaus.janino
			janino
			2.5.16
			jar
			compile
		

		
		
			antlr
			antlr
			2.7.7
			jar
			compile
		
	

1.mvn dependency:list:

可查看当前项目的已解析依赖。强直接在当前项目pom中声明的依赖定义为顶层依赖,而这些顶层依赖的依赖则定义为第二层依赖,以此类推。

[INFO] --- maven-dependency-plugin:2.8:list (default-cli) @ JTViewer ---
[INFO] 
[INFO] The following files have been resolved:
[INFO]    jreality:colorpicker:jar:1.0:system
[INFO]    jreality:jrworkspace:jar:1.0:system
[INFO]    org.beanshell:bsh:jar:2.0b4:compile
[INFO]    xpp3:xpp3_min:jar:1.1.4c:compile
[INFO]    jreality:beans:jar:1.0:system
[INFO]    com.thoughtworks.xstream:xstream:jar:1.3.1:compile
[INFO]    org.codehaus.janino:janino:jar:2.5.16:compile
[INFO]    jreality:jReality:jar:1.0:system
[INFO]    antlr:antlr:jar:2.7.7:compile
[INFO]    jreality:jterm:jar:1.0:system
[INFO]    jreality:smrj.jar:jar:1.0:system
[INFO]    jreality:sunflow.jar:jar:1.0:system
[INFO]    com.lowagie:itext:jar:2.1.3:compile
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS


2. mvn dependency:tree

能够查看依赖树,通过这棵树能够很清楚的看到某个依赖是通过哪条路径引入进来的。

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ JTViewer ---
[INFO] uk.ac.liverpool:JTViewer:jar:0.7.1  
[INFO] +- jreality:jReality:jar:1.0:system
[INFO] +- jreality:jrworkspace:jar:1.0:system
[INFO] +- jreality:jterm:jar:1.0:system
[INFO] +- jreality:smrj.jar:jar:1.0:system
[INFO] +- jreality:sunflow.jar:jar:1.0:system
[INFO] +- jreality:colorpicker:jar:1.0:system
[INFO] +- jreality:beans:jar:1.0:system
[INFO] +- com.lowagie:itext:jar:2.1.3:compile
[INFO] +- com.thoughtworks.xstream:xstream:jar:1.3.1:compile
[INFO] |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] +- org.beanshell:bsh:jar:2.0b4:compile
[INFO] +- org.codehaus.janino:janino:jar:2.5.16:compile
[INFO] \- antlr:antlr:jar:2.7.7:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.080 s
[INFO] Finished at: 2016-10-13T10:04:12+08:00
[INFO] Final Memory: 13M/217M
[INFO] ------------------------------------------------------------------------


注意:

JTViewer:jar:0.7.1  //项目编译后的打包;

“+-”后面的jar包是顶层依赖包,在pom中进行了声明;

“|  \-”后面的jar包是引用包,未在pom中声明;

只要声明顶层包,其对应的引用包会自动去仓库中下载;

“\-”,不管在pom文件中最后一个依赖引用是哪个,其前缀都是“\-”,如最后一个是:\- antlr:antlr:jar:2.7.7:compile,或最后一个是 \- jreality:jReality:jar:1.0:system,而该依赖是重要依赖,不可缺少,即 ”\-” 仅表后最后一个依赖引用;


2. mvn dependency:analyze

可以帮助分析当前项目的依赖。

[INFO] --- maven-dependency-plugin:2.8:analyze (default-cli) @ JTViewer ---
[WARNING] Unused declared dependencies found:
[WARNING]    jreality:jrworkspace:jar:1.0:system
[WARNING]    jreality:jterm:jar:1.0:system
[WARNING]    jreality:smrj.jar:jar:1.0:system
[WARNING]    jreality:sunflow.jar:jar:1.0:system
[WARNING]    jreality:colorpicker:jar:1.0:system
[WARNING]    jreality:beans:jar:1.0:system
[WARNING]    com.lowagie:itext:jar:2.1.3:compile
[WARNING]    org.beanshell:bsh:jar:2.0b4:compile
[WARNING]    org.codehaus.janino:janino:jar:2.5.16:compile
[WARNING]    antlr:antlr:jar:2.7.7:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.697 s
[INFO] Finished at: 2016-10-13T10:51:20+08:00
[INFO] Final Memory: 14M/217M
[INFO] ------------------------------------------------------------------------

结果会有2部分:

首先是"Used declared dependencies found",指项目中使用到,但是没有显示声明的依赖,如果有的话,需要在pom中添加依赖声明;

另外就是“Unused declared dependencies found”,指项目中未使用的,但是显示声明的依赖,但是对于这样的依赖,不能直接删除,要仔细分析。因为dependency:analyze只会分析编译主代码和测试代码用到的依赖,一些执行测试和运行时需要的依赖是发现不了的。但是很显然有些依赖是必须的,不能删除。所以要小心寻找无用的依赖信息,然后再删除。


通过以上分析,可以需要与不需要的依赖,达到优化作用。

你可能感兴趣的:(maven)