java在项目中创建目录结构图,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

9945a1879b32158fc9fef118a4a03f2d.png

另外一种方法,我们可以使用三方插件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项目的项目目录结构。0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值