设为首页 加入收藏

TOP

Gradle创建项目目录结构
2014-11-24 12:07:19 来源: 作者: 【 】 浏览:0
Tags:Gradle 创建 项目 目录 结构

如何使用Gradle创建如maven那样的项目结构呢 ?


gradle不像maven那样有固定的项目结构,gradle原声API是不支持的,要想做到这一点,我们可以自定义一个task。


1. 创建一个createJavaProject文件夹


2. 在此目录下创建gradle的构建脚本,build.gradle,内容如下:


apply plugin: 'java'

task "create-dirs" << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}


3. 命令行运行 gradle create-dirs



另外一种方法,我们可以使用三方插件templates。


1. gradle templates 插件可以轻松的创建项目结构,http://tellurianring.com/wiki/gradle/templates,但是最新版本gradle1.0好像安装不上,不知道什么问题,我们也可以使用其他方式用上这个插件。


2. 下载最新的templates-xx.jar,https://launchpad.net/gradle-templates/+download 放在gradle 的lib/plugins目录下面。


3. 建个项目文件夹createJavaProject, 新建gradle构建脚本build.gradle,内容如下:


buildscript{
repositories {
flatDir dirs: "${gradle.gradleHomeDir}/lib/plugins"
}
dependencies {
classpath ':templates:1.2'
}
}
apply plugin: 'templates'


4. 执行gradle tasks, 就会看到如下tasks:


Template tasks
--------------
createGradlePlugin - Creates a new Gradle Plugin project in a new directory named after your project.
createGroovyClass - Creates a new Groovy class in the current project.
createGroovyProject - Creates a new Gradle Groovy project in a new directory named after your project.
createJavaClass - Creates a new Java class in the current project.
createJavaProject - Creates a new Gradle Java project in a new directory named after your project.
createScalaClass - Creates a new Scala class in the current project.
createScalaObject - Creates a new Scala object in the current project.
createScalaProject - Creates a new Gradle Scala project in a new directory named after your project.
createWebappProject - Creates a new Gradle Webapp project in a new directory named after your project.
exportAllTemplates - Exports all the default template files into the current directory.
exportGroovyTemplates - Exports the default groovy template files into the current directory.
exportJavaTemplates - Exports the default java template files into the current directory.
exportPluginTemplates - Exports the default plugin template files into the current directory.
exportScalaTemplates - Exports the default scala template files into the current directory.
exportWebappTemplates - Exports the default webapp template files into the current directory.
initGradlePlugin - Initializes a new Gradle Plugin project in the current directory.
initGroovyProject - Initializes a new Gradle Groovy project in the current directory.
initJavaProject - Initializes a new Gradle Java project in the current directory.
initScalaProject - Initializes a new Gradle Scala project in the current directory.
initWebappProject - Initializes a new Gradle Webapp project in the current directory.


5. gradle createJavaProject创建java项目的项目目录结构。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇FL2440的U-boot-2010.09移植(七.. 下一篇Gradle 打包 Groovy 脚本成 jar与..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)