maven junit.framework不存在问题解决

问题

在使用maven进行一个工程的编译,已加入junit包的依赖,编译的时候却总是报“junit.framework不存在”错误。

pom.xml中junit包加入如下:

[html] view plain copy
 
  1. <dependency>  
  2.     <groupId>junit</groupId>  
  3.     <artifactId>junit</artifactId>  
  4.     <version>4.12</version>  
  5.     <scope>test</scope>  
  6. </dependency>  

解决

试了N多方法,包括加入junit-dep包,依然解决不了问题,后来在加junit-dep包的时候发现,原来多了一个scope属性,将scope属性去掉后恢复正常。

[html] view plain copy
 
  1. <dependency>  
  2.     <groupId>junit</groupId>  
  3.     <artifactId>junit</artifactId>  
  4.     <version>4.12</version>  
  5. </dependency>  


原来依赖加入scope属性后,就会被约束在该生命周期内,在compile阶段不引入test阶段的依赖,也就是说编译阶段该依赖无效。

如果修改scope属性,则也可以正常运行:

[html] view plain copy
 
  1. <dependency>  
  2.     <groupId>junit</groupId>  
  3.     <artifactId>junit</artifactId>  
  4.     <version>4.12</version>  
  5.     <scope>compile</scope>  
  6. </dependency>  



原文地址:https://www.cnblogs.com/qianqiu-1026/p/8520581.html