这maven大行其道的当下,咱们已经不用再使用MyEclipse 或是Intellij IDEA给咱们提供的新建项目那么繁琐的流程了,按照须要和规则咱们能够快速的完成一个项目的新建。java
有别于Maven使用骨架的方式能够一步到位的新建好项目,Gradle还须要咱们手动的添加一些文件夹,幸亏Gradle的文件夹规则和Maven差很少,顺手新建几个文件夹就行了。git
忽略代码咱们直接上build.gradle. 下面是一个普通java项目github
//插件 java插件 和 application插件 若是想看都有什么task 能够执行gradle tasks apply plugin: 'java' apply plugin: 'application' sourceCompatibility = 1.5 version = '1.0' //运行的项目入口,里面一般有main方法。 mainClassName = 'com.lee.study.HelloGradle' repositories { mavenCentral() /*maven{ credentials{ username 'admin' password 'admin123' } url "http://localhost:8081/nexus/content/groups/public/" }*/ } //jar依赖 dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' }
经过上面的设置咱们能够编译 打包 运行 生成javadoc等各类操做,web
下面咱们在看一个web 项目的build.gradlespring
//插件 war 插件 jetty 插件 tomcat插件 apply plugin: 'war' apply plugin: 'jetty' //apply plugin: 'tomcat' //sourceCompatibility = 1.5 //这是IDEA新建项目带的 好像是过期了 so 我注释起来了,不是tomcat插件的配置 version = '1.0' repositories { mavenCentral() maven{ credentials{ username 'admin' password 'admin123' } url "http://localhost:8081/nexus/content/groups/public/" } } dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' compile 'org.springframework:spring-webmvc:3.2.0.RELEASE' runtime 'javax.servlet:jstl:1.1.2' //tomcat 插件的配置 /* def tomcatVersion = '7.0.11' tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}" tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") { exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj' }*/ } tomcat 插件的配置 /* tomcat { httpPort = 8090 stopPort = 8091 //httpsPort = 8091 //enableSSL = true } tomcatRun{ contextPath= 'server' URIEncoding= 'UTF-8' reloadable = 'true' } */ //jetty 插件的的配置 httpPort = 8090 stopPort = 8091 stopKey = "kelljetty" jettyRun{ contextPath = 'server' reload = 'automatic' scanIntervalSeconds = 10 } //tomcat 插件的配置 /* buildscript { repositories { jcenter() } dependencies { classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.2.3' } }*/
上面的web 项目我把tomcat plugin的都注释起来了,我本人在项目开发中比较喜欢使用tomcat的插件,无论是Maven仍是Gradle中,可是大多数人都喜欢jetty来进行嵌入式的服务器用于开发。apache
给喜欢Tomcat的同窗提供一下Gradle tomcat plugin的 GitHub地址api
https://github.com/bmuschko/gradle-tomcat-plugin tomcat
我就是照着配得 很简单,要是添加什么按照readme中得介绍配就好了服务器
http://git.oschina.net/lixuwei/hello-gradlemvc
这是我写得一个小例子。