gradle templates plugins

项目GitHub地址

gradle不能像maven一样直接构建项目目录结构,每次都需要自己编写build.gradle文件然后创建task
这怎么能忍,于是大神们写了这样一个插件

这个插件很程度上简化了工作量
先看人家的介绍

The standard way to install this plugin is by adding the following to your build.gradle file:

buildscript {
    repositories { 
      maven {
         url 'http://dl.bintray.com/cjstehno/public' 
      }
    } 
    dependencies { 
         classpath 'gradle-templates:gradle-templates:1.5'
    }
}
apply plugin:'templates'

但这人很麻烦,每建一个项目都要编辑一次这个文件多麻烦
那么有没有全局配置呢?当然有

Using Gradle init scripts, it’s possible to install the >Templates plugin globally – Allowing you to execute gradle createJavaProject anywhere, even when there isn’t a build.gradle file present in the directory.
Simply add the following to your ~/.gradle/init.gradle script:

gradle.beforeProject { prj -> prj.apply from: 'http://www.tellurianring.com/projects/gradle-plugins/gradle-templates/apply.groovy'}

意思就是在/home/username/.gradle/ 目录下编辑init.gradle文件(如果没有就创建之),添加上面哪一行代码。
这样无论你在那个目录下只要输入

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.

然后只需要在你只需要输入

gradle createJavaProject

就可以创建java项目了,是不是很简单!
有关更多gradle请看下一篇

    原文作者:NoOneDev
    原文地址: https://www.jianshu.com/p/5bf59de4e636
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞