Gradle是一种自动化建构工具,使用DSL来声明项目设置。通过Gradle,可以对项目的依赖进行配置,并且自动下载所依赖的文件,使得构建项目的效率大大提高。

1. 安装Gradle

下载Gradle的最新版本,并解压,设置环境变量GRADLE_HOME,并且将%GRADLE_HOME%\bin添加到Path里面;

2. 安装Gradle插件

在Eclipse的Help->Eclipse Marketplace中搜索Gradle,安装Buildship;

3. 创建Gradle项目

选择File->New->Other->Gradle->Gradle Project,新建一个Gradle项目:

设置Gradle路径以及Java路径:

4. 将Project转换成Web Project

右键单击项目,选择Properties->Project Facets,选择Dynamic Web Module:

5.  配置Gradle

打开build.gradle文件,进行如下编辑:

/*
* This build file was auto generated by running the Gradle 'init' task
* by 'simon' at '16-11-17 涓嬪崍2:49' with Gradle 3.2
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/3.2/userguide/tutorial_java_projects.html
*/ // Apply the java plugin to add support for Java
apply plugin: 'java' // In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
} // In this section you declare the dependencies for your production and test code
dependencies {
// struts library
compile group: 'org.apache.struts', name: 'struts2-core', version: '2.3.24.1'
compile 'org.apache.struts:struts2-spring-plugin:2.3.24.1'
compile 'org.apache.struts:struts2-json-plugin:2.3.24.1' // spring library
compile group: 'org.springframework', name: 'spring-core', version: '4.2.3.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version: '4.2.3.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version: '4.2.3.RELEASE'
compile group: 'org.springframework', name: 'spring-aop', version: '4.2.3.RELEASE'
compile group: 'org.springframework', name: 'spring-aspects', version: '4.2.3.RELEASE'
compile group: 'org.springframework', name: 'spring-jdbc', version: '4.2.3.RELEASE' // hibernate library
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.0.1.Final' // common library
compile 'org.slf4j:slf4j-api:1.7.13'
testCompile 'junit:junit:4.12' }

仓库使用了jcenter(),也可以使用mavenCentral(),不过jcenter()更好,包含了mavenCentral()。依赖关系中配置了Struts、Spring、Hibernate的文件,以及其他一些常用的文件。

点击Gradle Executions的Run按钮,就开始自动下载上述配置的依赖文件,是不是比以前方便多了?当然,如果已经有了这些文件,也可以依赖本地的文件。

最新文章

  1. Neil·Zou 语录三
  2. 【转】IE8浏览器无法保存Cookie的解决方法
  3. Android 短视频拍摄、拍照滤镜 第三方库SDK
  4. bringSubviewToFront和insertSubview: atIndex:
  5. 【模板】【转载】区间dp
  6. io多路复用,select,笔记
  7. EmberJs之使用Ember-Data
  8. Java内存管理和垃圾回收
  9. HDU 5438 Ponds (DFS,并查集)
  10. 【python自动化第八篇:网络编程】
  11. js与后台交互详述(入门篇)
  12. java虚拟机 jvm 栈数据区
  13. oracle 查看后台正在执行的脚本
  14. shell 判断文件夹或文件是否存在
  15. JVM探秘5---JVM监控命令大全
  16. .NET拾忆:EventLog(Windows事件日志监控)
  17. shell流程控制与循环结构
  18. 前端表单中有按钮button自动提交表单
  19. IOS 应用官方接口地址
  20. python2 python3共存解决方案

热门文章

  1. 在Linux系统下运行微信Web开发者工具
  2. Python学习
  3. ES6之let命令详解
  4. arcgis api for js入门开发系列四地图查询(含源代码)
  5. 【干货分享】流程DEMO-人员调动流程
  6. oracle 存储过程
  7. 绿色版的Linux.NET——“Jws.Mono”
  8. 通过几个Hello World感受.NET Core全新的开发体验
  9. 图形数据库Neo4J简介
  10. Dijkstra 单源最短路径算法