LoginSignup
11
11

More than 5 years have passed since last update.

build.gradleひな形メモ

Last updated at Posted at 2014-04-26

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

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

コマンドラインプログラム

Java

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

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

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

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'
        }
    }
}
11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11