手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Gradle创建项目目录结构

[日期:2012-07-02] 来源:Linux社区  作者:devhubs [字体: ]

如何使用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项目的项目目录结构。

linux
相关资讯       Maven  Gradle 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款