`
rensanning
  • 浏览: 3515249 次
  • 性别: Icon_minigender_1
  • 来自: 大连
博客专栏
Efef1dba-f7dd-3931-8a61-8e1c76c3e39f
使用Titanium Mo...
浏览量:37505
Bbab2146-6e1d-3c50-acd6-c8bae29e307d
Cordova 3.x入门...
浏览量:604415
C08766e7-8a33-3f9b-9155-654af05c3484
常用Java开源Libra...
浏览量:678191
77063fb3-0ee7-3bfa-9c72-2a0234ebf83e
搭建 CentOS 6 服...
浏览量:87346
E40e5e76-1f3b-398e-b6a6-dc9cfbb38156
Spring Boot 入...
浏览量:399876
Abe39461-b089-344f-99fa-cdfbddea0e18
基于Spring Secu...
浏览量:69090
66a41a70-fdf0-3dc9-aa31-19b7e8b24672
MQTT入门
浏览量:90521
社区版块
存档分类
最新评论

Gradle入门(2) -- 创建模板工程

阅读更多
Gradle的标准模板和Maven的是一样的:

引用
APP_PROJECT_ROOT
|-- build.gradle
|-- build/
`-- src
    |-- main
    |   |-- groovy/
    |   |-- java/
    |   `-- resources/
    `-- test
        |-- groovy/
        |-- java/
        `-- resources/


但是目前Gradle不像Maven那样通过命令行就能生成模板工程。可以自己写脚本(Task)生成模板工程,也可以使用Plugin。

按照以下步骤安装插件:

(1)从https://launchpad.net/gradle-templates 下载templates-1.2.jar 后放入一个新建的文件夹$GRADLE_HOME\customPlugins中。

(2)编写一个build.gradle
引用
buildscript{
repositories {
flatDir dirs: "${gradle.gradleHomeDir}/customPlugins"
}
dependencies {
classpath ':templates:1.2'
}
}

apply plugin: 'templates'


(3)执行脚本
引用
D:\>gradle --stacktrace
:help

Welcome to Gradle 1.0.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

BUILD SUCCESSFUL

Total time: 5.188 secs


(4)查看Task

引用
D:\>gradle task
:tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Help tasks
----------
dependencies - Displays the dependencies of root project ''.
help - Displays a help message
projects - Displays the sub-projects of root project ''.
properties - Displays the properties of root project ''.
tasks - Displays the tasks runnable from root project '' (some of the displayed tasks may belong to
subprojects).

Template tasks
--------------
createGradlePlugin - Creates a new Gradle Plugin project in a new directory named after your projec
.
createGroovyClass - Creates a new Groovy class in the current project.
createGroovyProject - Creates a new Gradle Groovy project in a new directory named after your proje
t.
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 proje
t.
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.

To see all tasks and more detail, run with --all.

BUILD SUCCESSFUL

Total time: 3.766 secs


(5)创建Java模板工程
引用
D:\>gradle createJavaProject
> Building > :createJavaProject
??> Project Name: TestRen

??> Group: [testren] testgroup

??> Version: [1.0] 1.0
:createJavaProject

BUILD SUCCESSFUL

Total time: 30.578 secs


(6)生成的工程
引用
TestRen
│  build.gradle
│  gradle.properties
│  LICENSE.txt

└─src
    ├─main
    │  ├─java
    │  └─resources
    └─test
        ├─java
        └─resources


(7)使用STS(SpringSource Tool Suite)导入工程,以后的构建就很方便了。




  • 大小: 10.5 KB
  • 大小: 15.2 KB
  • 大小: 18.3 KB
3
9
分享到:
评论
1 楼 huihai 2014-05-17  
https://launchpad.net/gradle-templates 下载templates-1.2.jar  这个找不到了,怎么弄呢,能不能传过?

相关推荐

Global site tag (gtag.js) - Google Analytics