build.gradleひな形メモ

よく使う build.gradle のひな形メモ。

不要な部分は適宜削除する。

#コマンドラインプログラム
##Java
```groovy:
apply plugin: 'application'

startScripts {
    applicationName = 'startScriptsName'
    mainClassName = 'main.class.Name'
}
distZip.baseName = 'distZipName'
jar.baseName = 'jarName'

sourceCompatibility = '1.7'
targetCompatibility = '1.7'

repositories {
    mavenCentral()
    
    maven {
        url 'repository url'
    }
}

dependencies {
    compile 'org.apache.commons:commons-lang3:3.2.1'
    
    testCompile 'junit:junit:4.11', {transitive = false}
    testCompile 'org.hamcrest:hamcrest-all:1.3'
}

apply plugin: 'eclipse'

eclipse {
    project {
        name = 'project-name'
    }
    
    def jreName = 'jre name'
    
    classpath {
        containers.clear()
        containers << 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/' + jreName
    }
}
```

##Groovy
```groovy:
apply plugin: 'application'
apply plugin: 'groovy'

startScripts {
    applicationName = 'startScriptsName'
    mainClassName = 'main.class.Name'
}
distZip.baseName = 'distZipName'
jar.baseName = 'jarName'

sourceCompatibility = '1.7'
targetCompatibility = '1.7'

repositories {
    mavenCentral()
    
    maven {
        url 'repository url'
    }
}

dependencies {
    compile 'org.apache.commons:commons-lang3:3.2.1'
    compile 'org.codehaus.groovy:groovy:2.2.1'
    
    testCompile 'junit:junit:4.11', {transitive = false}
    testCompile 'org.hamcrest:hamcrest-all:1.3'
}

apply plugin: 'eclipse'

eclipse {
    project {
        name = 'project-name'
    }
    
    def jreName = 'jre name'
    
    classpath {
        containers.clear()
        containers << 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/' + jreName
    }
}
```

#Web アプリケーション
##Java
```groovy:
apply plugin: 'war'

ext.javaVersion = '1.7'

sourceCompatibility = javaVersion
targetCompatibility = javaVersion

repositories {
    mavenCentral()
    
    maven {
        url 'repository url'
    }
}

dependencies {
    compile 'org.apache.commons:commons-lang3:3.2.1'
    
    providedCompile 'javax:javaee-api:7.0'
    // providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
    
    testCompile 'junit:junit:4.11', {transitive = false}
    testCompile 'org.hamcrest:hamcrest-all:1.3'
}

apply plugin: 'eclipse-wtp'

eclipse {
    project {
        name = 'project-name'
    }
    
    def jreName = 'jre name'
    
    classpath {
        containers.clear()
        containers << 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/' + jreName
    }
    
    wtp {
        facet {
            facet name: 'jst.java', version: javaVersion
            facet name: 'jst.web', version: '3.0'
        }
        
        component {
            deployName = 'deploy name'
            contextPath  = 'context root name'
        }
    }
}
```

##Groovy
```groovy:
apply plugin: 'war'
apply plugin: 'groovy'

ext.javaVersion = '1.7'

sourceCompatibility = javaVersion
targetCompatibility = javaVersion

repositories {
    mavenCentral()
    
    maven {
        url 'repository url'
    }
}

dependencies {
    compile 'org.apache.commons:commons-lang3:3.2.1'
    compile 'org.codehaus.groovy:groovy:2.2.1'
    
    providedCompile 'javax:javaee-api:7.0'
    // providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
    
    testCompile 'junit:junit:4.11', {transitive = false}
    testCompile 'org.hamcrest:hamcrest-all:1.3'
}

apply plugin: 'eclipse-wtp'

eclipse {
    project {
        name = 'project-name'
    }
    
    def jreName = 'jre name'
    
    classpath {
        containers.clear()
        containers << 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/' + jreName
    }
    
    wtp {
        facet {
            facet name: 'jst.java', version: javaVersion
            facet name: 'jst.web', version: '3.0'
        }
        
        component {
            deployName = 'deploy name'
            contextPath  = 'context root name'
        }
    }
}
```