在Maven中dependencyManagement的作用其实相当于一个对所依赖jar包进行版本管理的管理器。
在dependencyManagement下申明的dependencies,Maven并不会去实际下载所依赖的jar包,而是在dependencyManagement中用一个Map记录了jar的三维坐标。
而被仅仅是被dependencies包裹的元素,Maven是会去仓库实际下载所需要的jar包的,而至于需要下载什么
版本的jar包就有两种判断途径:
1:如果dependencies里的dependency自己没有声明version元素,那么maven就
会倒dependencyManagement里面去找有没有对该artifactId和groupId进行过版本声明,如果有,就继承它,如果没有就会报错,告诉你必须为dependency声明一个version
2:如果dependencies中的dependency声明了version,那么无论dependencyManagement中有无对该jar的version声明,都以dependency里的version为准。
pom.xml
//只是对版本进行管理,不会实际引入jar
org.springframework
spring-core
3.2.7
//会实际下载jar包
org.springframework
spring-core
可以看到dependecies元素下的dependency里并没有声明版本,这是因为在manager中已经将版本管理起来了。
比如我们在项目中需要引入一个框架A的jar包:a.jar。而A框架的作者为了实现A框架又在其pom里面引入了spring框架,那么问题就来了,如果我们的项目也要用到spring框架,那spring框架的版本应该以谁的为准呢?
这可能就是dependencyManagement的作用了,你可以在dependencyManagement中对spring进行版本声明,然后你在dependencies中添加对A框架的引用,那么实际引入的spring版本就是你在dependencyManagement中声明的版本了。
maven中的 dependencies 和 dependencyManagement 的区别
参考phantomjs的API Reference,我们主要要利用的就是这个函数,它的usage如下:
evaluate(function, arg1, arg2, ...) {object}
Evaluates the given function in the context of the web page. The execution is sandboxed, the web page has no access to the phantom object and it can’t probe its own setting.
Example:
var page = require('webpage').create();
page.openfunction(status) {
var title = page.evaluate(function() {
return document.title;
});
console.log(title);
phantom.exit();
});