利用Gradle Task自动创建项目结构
2015-02-19 00:00
531 查看
摘要: 今天体验了下Gradle,总体感觉还不错,就是新建项目比较麻烦(可能是我不会用这个插件),随想通过Task实现项目结构的创建,果断网站一搜,还真有现成的,开心,收藏。
将下面代码加入到
<pre class="brush:groovy">
apply plugin: 'java'
task "create-dirs" << {
sourceSets*.java.srcDirs*.each {it.mkdirs()}
sourceSets*.resources.srcDirs*.each {it.mkdirs()}
}
</pre>
用gradle运行此任务:
<pre class="brush:shell">
$ gradle create-dirs
</pre>
生成的目录结构:
<pre>
.
├── build.gradle
└── src
├── main
│ ├── java
│ └── resources
└── test
├── java
└── resources
</pre>
如果是使用idea的话,只要在
<pre class="brush:groovy">
apply plugin: 'java'
apply plugin: 'idea'
</pre>
然后执行如下命令:
<pre class="brush:shell">
$ gradle idea
</pre>
以上命令会生成
**原文地址:**http://www.tuicool.com/articles/eyeeEf
Mark:我的构建脚本
<pre class="brush:groovy">
import org.gradle.plugins.ide.eclipse.model.Facet
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'jetty'
//设置 JDK 版本
sourceCompatibility = 1.8
targetCompatibility = 1.8
//设置 WebApp 根目录
webAppDirName = 'webapp'
//设置 Java 源码所在目录
//sourceSets.main.java.srcDir 'src/main/java'
sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/main/resources'
}
}
}
//设置 maven 库地址
repositories {
mavenCentral() // 中央库
maven { url 'http://maven.oschina.net/content/groups/public/' } // 自定义库地址
}
// 设置依赖
dependencies {
def SpringVersion = '4.1.4.RELEASE'
runtime group:'org.springframework', name:'spring-context', version:'4.1.4.RELEASE'
runtime group:'org.springframework', name:'spring-webmvc', version:'4.1.4.RELEASE'
runtime group:'org.aspectj', name:'aspectjrt', version:'1.8.1'
runtime group:'org.slf4j', name:'slf4j-api', version:'1.6.1'
runtime group:'org.slf4j', name:'jcl-over-slf4j', version:'1.6.1'
runtime group:'org.slf4j', name:'slf4j-log4j12', version:'1.6.1'
runtime group:'log4j', name:'log4j', version:'1.2.6'
runtime group:'javax.inject', name:'javax.inject', version:'1'
runtime group:'com.fasterxml.jackson.core', name:'jackson-databind', version:'2.4.1'
testRuntime group:'org.springframework', name:'spring-test', version:'4.1.4.RELEASE'
testRuntime group:'junit', name:'junit', version:'4.11'
// providedRuntime 'org.springframework:spring-context:4.1.4.RELEASE'
// providedCompile 'javax.servlet:servlet-api:2.5'
}
// 设置 Project Facets
eclipse {
wtp {
facet {
facet name: 'jst.web', type: Facet.FacetType.fixed
facet name: 'wst.jsdt.web', type: Facet.FacetType.fixed
facet name: 'jst.java', type: Facet.FacetType.fixed
facet name: 'jst.web', version: '3.0'
facet name: 'jst.java', version: '1.8'
facet name: 'wst.jsdt.web', version: '1.0'
}
}
}
task "create-dirs" << {
sourceSets*.java.srcDirs*.each {it.mkdirs()}
sourceSets*.resources.srcDirs*.each {it.mkdirs()}
}
</pre>
将下面代码加入到
build.gradle中:
<pre class="brush:groovy">
apply plugin: 'java'
task "create-dirs" << {
sourceSets*.java.srcDirs*.each {it.mkdirs()}
sourceSets*.resources.srcDirs*.each {it.mkdirs()}
}
</pre>
用gradle运行此任务:
<pre class="brush:shell">
$ gradle create-dirs
</pre>
生成的目录结构:
<pre>
.
├── build.gradle
└── src
├── main
│ ├── java
│ └── resources
└── test
├── java
└── resources
</pre>
如果是使用idea的话,只要在
build.gradle中添加idea插件就行了,如下:
<pre class="brush:groovy">
apply plugin: 'java'
apply plugin: 'idea'
</pre>
然后执行如下命令:
<pre class="brush:shell">
$ gradle idea
</pre>
以上命令会生成
out: file.iml,
file.ipr,
file.iws这三个文件,最后就可以打开intellij idea愉快的玩耍了。
**原文地址:**http://www.tuicool.com/articles/eyeeEf
Mark:我的构建脚本
<pre class="brush:groovy">
import org.gradle.plugins.ide.eclipse.model.Facet
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'jetty'
//设置 JDK 版本
sourceCompatibility = 1.8
targetCompatibility = 1.8
//设置 WebApp 根目录
webAppDirName = 'webapp'
//设置 Java 源码所在目录
//sourceSets.main.java.srcDir 'src/main/java'
sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/main/resources'
}
}
}
//设置 maven 库地址
repositories {
mavenCentral() // 中央库
maven { url 'http://maven.oschina.net/content/groups/public/' } // 自定义库地址
}
// 设置依赖
dependencies {
def SpringVersion = '4.1.4.RELEASE'
runtime group:'org.springframework', name:'spring-context', version:'4.1.4.RELEASE'
runtime group:'org.springframework', name:'spring-webmvc', version:'4.1.4.RELEASE'
runtime group:'org.aspectj', name:'aspectjrt', version:'1.8.1'
runtime group:'org.slf4j', name:'slf4j-api', version:'1.6.1'
runtime group:'org.slf4j', name:'jcl-over-slf4j', version:'1.6.1'
runtime group:'org.slf4j', name:'slf4j-log4j12', version:'1.6.1'
runtime group:'log4j', name:'log4j', version:'1.2.6'
runtime group:'javax.inject', name:'javax.inject', version:'1'
runtime group:'com.fasterxml.jackson.core', name:'jackson-databind', version:'2.4.1'
testRuntime group:'org.springframework', name:'spring-test', version:'4.1.4.RELEASE'
testRuntime group:'junit', name:'junit', version:'4.11'
// providedRuntime 'org.springframework:spring-context:4.1.4.RELEASE'
// providedCompile 'javax.servlet:servlet-api:2.5'
}
// 设置 Project Facets
eclipse {
wtp {
facet {
facet name: 'jst.web', type: Facet.FacetType.fixed
facet name: 'wst.jsdt.web', type: Facet.FacetType.fixed
facet name: 'jst.java', type: Facet.FacetType.fixed
facet name: 'jst.web', version: '3.0'
facet name: 'jst.java', version: '1.8'
facet name: 'wst.jsdt.web', version: '1.0'
}
}
}
task "create-dirs" << {
sourceSets*.java.srcDirs*.each {it.mkdirs()}
sourceSets*.resources.srcDirs*.each {it.mkdirs()}
}
</pre>
相关文章推荐
- 使用Gradle自动创建Java项目结构
- 使用Gradle自动创建Java项目结构
- 使用Gradle自动创建Java项目结构
- 使用Gradle自动创建Java项目结构
- 创建TFS团队项目时自动建立代码库的文件夹结构
- [SpringBoot学习]-IDEA创建Gradle多Module结构的SpringBoot项目
- Maven项目目录结构与自动创建maven目录
- Gradle创建项目目录结构
- 3.跟我学Gradle-快速入门,了解创建和指定Gradle项目的标准目录结构
- 利用vue-cli创建的vue项目结构解析
- Maven利用Archetype自动生成项目目录结构
- Maven利用Archetype自动生成项目目录结构
- 在STS中利用Gradle创建web项目
- idea创建Gradle项目无法自动生成src目录
- Gradle创建项目目录结构
- 使用脚本自动创建AD中的层次化结构容器及对象 推荐
- 利用Hibernate工具,通过xml文件自动创建表
- EJB3.x:部署(卸载)EntityBean时自动创建(删除)表结构
- PS创建动作并利用批处理命令自动处理多图片--转
- 利用动态创建层技术实现无冗余代码为表单自动添加错误提示