2014-06-18 112 views
1
gradle 1.12 
Fedora 20 

我第一次使用gradle構建我的java程序。我使用emacs,因爲我不喜歡使用eclipse。因爲我喜歡在cmd行上做所有事情。gradle可以創建java項目目錄結構嗎?

Gradle希望在src/main/java下找到您的生產源代碼,並在src/test/java下找到您的測試源代碼。此外,在src/main/resources下的任何文件

我想知道是否有一個命令,我可以在gradle中使用它來自動創建此項目結構?

我可以編寫一個腳本文件,但在此之前,我想知道gradle是否可以執行此操作。

提前許多感謝,

回答

5

目前還不能內置的方式來創建目錄結構,但gradle init可能會照顧這在某些時候。

UPDATE:現在可通過Gradle init plugin獲得。 樣本用法是:

gradle init --type java-library 
+0

你試過看着HTTPS ://github.com/townsfolk/gradle-templates。 – Ithar

3

您可以使用gradle-templates

第1步:添加模板插件來build.gradle

group 'com.hireartists.consumer.repository' 
version '1.0-SNAPSHOT' 

apply plugin: 'java' 
apply plugin: 'idea' 

sourceCompatibility = 1.8 

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile 'org.springframework:spring-webmvc:4.2.1.RELEASE' 
    compile 'org.apache.kafka:kafka_2.10:0.8.2.2' 
    compile 'javax.servlet:jstl:1.2' 
    testCompile group: 'junit', name: 'junit', version: '4.11' 
} 

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

apply plugin:'templates' 

STEP 2:看你需要

任務
./gradlew 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. 

步驟3:應用

./gradlew initWebappProject 
> Building 0% > :initWebappProject 
templates> Use Jetty Plugin? (Y|n) [n] n 
:initWebappProject 

BUILD SUCCESSFUL 

Total time: 12.057 secs 

第4步的任務是:你可以看到該文件夾​​結構現在

prayag-top:hire-artists-consumer prayagupd$ ll src/main/ 
total 0 
drwxr-xr-x 2 prayagupd staff 68 Oct 31 12:48 java 
drwxr-xr-x 2 prayagupd staff 68 Oct 31 12:48 resources 
drwxr-xr-x 3 prayagupd staff 102 Oct 31 12:48 webapp 

更多閱讀https://github.com/townsfolk/gradle-templates#installation