#现在市面用到的项目构建工具有三种:Ant、Maven和Gradle;今天我们就来说说Maven和Gardle的一些区别?
现在说说为什么要使用项目构建工具?
在以前,这些操作都是需要我们手动去完成的。比如当引入一个外部依赖时,我们要专门去相应的地方拷贝得到jar包,或者得到源码编译出jar包,然后复制到classpath目录下。写完代码后,我们需要手动使用编译工具编译,然后手动去运行测试工具进行单元测试,如果没问题的话,再手动打包成war包,然后手动上传到服务器指定目录部署。
一个项目下来我们将会在这些与写代码无关的事情上浪费大量时间,而这些行为很明显是重复的,完全可以编写出相应的程序来帮助我们自动的完成这一系列的操作。而且多人合作时,每个人使用的外部依赖库的版本可能不一样,当合并项目后有可能会因为版本的不同带来BUG,而且这些BUG非常不容易让人发现,人们急需一个统一管理第三方依赖的工具。于是build工具出现了。
比较突出的区别就是依赖上面的区别?
maven依赖编写;(xml语言编写)
<properties>
<kaptcha.version>2.3</kaptcha.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.kaptcha</groupId>
<artifactId>kaptcha</artifactId>
<version>${kaptcha.version}</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
转换成Gradle脚本后是这样的,比较简洁;(groovy语言编写)
dependencies {
compile('org.springframework:spring-core:2.5.6')
compile('org.springframework:spring-beans:2.5.6')
compile('org.springframework:spring-context:2.5.6')
compile('com.google.code.kaptcha:kaptcha:2.3:jdk15')
testCompile('junit:junit:4.7')
}
工具下载地址:
https://maven.apache.org/download.cgi
gradle: https://gradle.org
配置环境变量:
变量名: GRADLE_HOME
变量值: 你自己的gradle文件目录(如图)
变量值: %GRADLE_HOME%\bin (如图)