Gradleでプロジェクトテンプレートを作成
Gradleでプロジェクト作成時に、ディレクトリも一緒に作成する方法のめも
環境
$ gradle -v ------------------------------------------------------------ Gradle 2.1 ------------------------------------------------------------ Build time: 2014-09-08 10:40:39 UTC Build number: none Revision: e6cf70745ac11fa943e19294d19a2c527a669a53 Groovy: 2.3.6 Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013 JVM: 1.7.0_51 (Oracle Corporation 24.51-b03) OS: Mac OS X 10.10 x86_64
プラグインを使う(^o^)
- Gradle Templates Plugin
適当なディレクトリに移動後、下記の内容でbuild.gradle
を作成
今回は
/Users/USER_NAME/workspace/gradle
ディレクトリ内で作成
buildscript { repositories { maven { url 'http://dl.bintray.com/cjstehno/public' } } dependencies { classpath 'gradle-templates:gradle-templates:1.5' } } apply plugin:'templates'
タスクを確認
$ gradle tasks :tasks ------------------------------------------------------------ All tasks runnable from root project ------------------------------------------------------------ Build Setup tasks ----------------- init - Initializes a new Gradle build. [incubating] wrapper - Generates Gradle wrapper files. [incubating] Help tasks ---------- components - Displays the components produced by root project 'java'. dependencies - Displays all dependencies declared in root project 'java'. dependencyInsight - Displays the insight into a specific dependency in root project 'java'. help - Displays a help message projects - Displays the sub-projects of root project 'java'. properties - Displays the properties of root project 'java'. tasks - Displays the tasks runnable from root project 'java'. 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. To see all tasks and more detail, run with --all. BUILD SUCCESSFUL Total time: 4.414 secs
今回はsample_webapp
という名前でWebapp
プロジェクトを作成
プロジェクトは'/Users/USER_NAME/workspace/gradle'以下に作成するものとする
$ gradle createWebappProject > Building 0% > :createWebappProject templates> Project Name: sample_webapp # プロジェクト名を入力 templates> Project Parent Directory: [/Users/USER_NAME/workspace/gradle] # プロジェクトの親ディレクトリ templates> Use Jetty Plugin? (Y|n) [n] # Jetty Pluginを利用するか(そのまんま・・・) templates> Group: [sample_webapp] # グループ名?を設定 templates> Version: [0.1] # プロジェクトのバージョン :createWebappProject BUILD SUCCESSFUL Total time: 28.047 secs
作成されたディレクトリ構造はこんな感じ
$ ls -1R sample_webapp LICENSE.txt build.gradle gradle.properties src sample_webapp/src: main test sample_webapp/src/main: java resources webapp sample_webapp/src/main/java: sample_webapp/src/main/resources: sample_webapp/src/main/webapp: WEB-INF sample_webapp/src/main/webapp/WEB-INF: web.xml sample_webapp/src/test: java resources sample_webapp/src/test/java: sample_webapp/src/test/resources:
プロジェクト用のディレクトリが作成されてる(^o^) gradleのデフォルトのタスクには含まれてないんですかね。。
Written with StackEdit.