今天第一次利用gradle构建工具。如果你想问 Maven和Gradle的区别 ,请自行去百度吧,因为我也说不上来,哈哈哈~~~~~~反正maven现在正在落后,而gradle正在崛起!
1、首先在eclipse中安装Gradle的插件
help>Eclipse Marketplace 搜索Gradle即可 我安装的是黑色小象的那个 名字叫做‘Buildship Gradle Integration 2.0’
2、创建Gradle工程
File》new》other》gradle文件夹》Gradle project 点击next 出现如下界面
继续点击next:
取个工程名,第一次建点击next 要进行一些配置
这是你安装的gradle的地址,然后点击next 会自动找jdk
点击finish就可以啦 目录结构如下:
在build.gradle中可以对其进行配置,依赖包什么的 比maven会简单点
我的build.gradle的内容是:
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* user guide available at https://docs.gradle.org/3.5.1/userguide/java_library_plugin.html
*/
// Apply the war plugin to add support for Java
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
// 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()
}
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-beans', version: '4.2.4.RELEASE'
compile group: 'org.springframework', name: 'spring-context', version: '4.2.4.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version: '4.2.4.RELEASE'
compile group: 'org.springframework', name: 'spring-webmvc', version: '4.2.4.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'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:21.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
等你加入依赖包以后 会自动下载,也可以自己弄 在项目上右击》gradle》refresh gradle project
3、下面就可以运行在tomcat上 重要的是 标注红色的代码 一定要用 不然是不能部署到tomcat中的。
然后就启动tomcat 在浏览器中输入地址 就可以啦
恭喜你!完成了gradle工程部署到tomcat上了。
如果有写的不对的地方 ,请留言指正!共同进步!