Skip to content

Instantly share code, notes, and snippets.

@littleiffel
Created August 31, 2015 13:54
Show Gist options
  • Save littleiffel/4ed8afd8a62435eb91b5 to your computer and use it in GitHub Desktop.
Save littleiffel/4ed8afd8a62435eb91b5 to your computer and use it in GitHub Desktop.
buildscript {
repositories {
jcenter()
maven {
url "http://repository.codehaus.org"
}
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.1.2"
classpath 'org.ajoberstar:gradle-git:1.2.0'
classpath 'net.java.dev.jets3t:jets3t:0.9.3'
}
}
/*********************************
Configuration
*********************************/
String customAwsDeployKey = ''
String customAwsDeploySecret = ''
String customAwsDeployBucketName = ''
/*********************************
Versioning
*********************************/
group = "eevol"
ext.buildTimestamp = new Date().format('yyyy-MM-dd HH:mm:ss')
version = new ProjectVersion(0, 1, System.env.BUILD_NUMBER).toString()
class ProjectVersion {
Integer major
Integer minor
String build
ProjectVersion(Integer major, Integer minor, String build) {
this.major = major
this.minor = minor
this.build = build
}
@Override
String toString() {
String fullVersion = "$major.$minor"
if (build) {
fullVersion += ".$build"
}
fullVersion
}
}
/*********************************
Gradle Plugins
*********************************/
apply plugin: "grails"
apply plugin: 'org.ajoberstar.grgit'
/*********************************
Grails Plugin Config
*********************************/
grails {
grailsVersion = "2.5.1"
}
repositories {
maven { url "http://maven.eevol.lu/nexus/content/repositories/central/" }
maven { url "http://maven.eevol.lu/nexus/content/repositories/grails/" }
maven { url "http://maven.eevol.lu/nexus/content/repositories/grails-plugins/" }
maven { url "http://maven.eevol.lu/nexus/content/repositories/central-bintray/" }
maven { url "http://maven.eevol.lu/nexus/content/repositories/scribe/" }
maven { url "http://maven.eevol.lu/nexus/content/repositories/hibernatespatial/" }
maven { url "http://maven.eevol.lu/nexus/content/repositories/geotools/" }
maven { url "http://maven.eevol.lu/nexus/content/repositories/boundlessgeo/" }
maven { url "http://maven.eevol.lu/nexus/content/repositories/snapshots/"}
jcenter()
grails.central()
}
dependencies {
runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
// Base Plugins
bootstrap "org.grails.plugins:tomcat:7.0.55.3"
compile "org.grails.plugins:localizations:1.8.11-SNAPSHOT"
compile "org.grails.plugins:scaffolding:2.1.2"
compile "org.grails.plugins:cache:1.1.8"
runtime("org.grails.plugins:hibernate4:4.3.10") {
exclude module: 'xml-apis'
}
runtime "org.grails.plugins:database-migration:1.4.0"
compile "org.grails.plugins:spring-security-core:2.0-RC4"
compile "org.grails.plugins:spring-security-ui:1.0-RC2"
// Asset / View related Plugins
compile "org.grails.plugins:sass-asset-pipeline:2.3.1"
compile "org.grails.plugins:coffee-asset-pipeline:2.0.7"
compile("org.grails.plugins:filterpane:2.4.7"){
exclude module: 'asset-pipeline'
}
compile "org.grails.plugins:create-domain-uml:0.5"
// Test Helper Plugins
test "org.spockframework:spock-core:1.0-groovy-2.4"
test "org.seleniumhq.selenium:selenium-firefox-driver:2.42.2"
test "org.gebish:geb-spock:0.9.3"
test("com.github.detro.ghostdriver:phantomjsdriver:1.0.4") {
transitive = false
}
test "org.grails.plugins:build-test-data:2.4.0"
test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
}
/*********************************
Grails Testing Tasks
*********************************/
import org.grails.gradle.plugin.tasks.GrailsTestTask
import org.grails.gradle.plugin.tasks.GrailsTask
import org.grails.gradle.plugin.tasks.GrailsWarTask
task testUnit(type: GrailsTestTask) {
testResultsDir = file('build/reports/test-unit')
phases = ['unit:']
}
task testIntegration(type: GrailsTestTask) {
jvmOptions {
minHeapSize = '1g'
maxHeapSize = '1g'
jvmArgs("-XX:MaxPermSize=512m")
}
testResultsDir = file('build/reports/test-integration')
phases = ['integration:']
}
task testFunctional(type: GrailsTestTask) {
jvmOptions {
minHeapSize = '1g'
maxHeapSize = '1g'
jvmArgs("-XX:MaxPermSize=512m")
}
testResultsDir = file('build/reports/test-functional')
phases = ['functional:']
}
test.enabled = false
check.dependsOn = [testUnit, testIntegration, testFunctional]
/*********************************
Grails Codenarc Tasks
*********************************/
task codenarc(type: GrailsTask) {
command "codenarc"
}
/*********************************
Build War Tasks
*********************************/
task createBuildInfo(dependsOn: clean) {
def buildInfoFile = new File("application.properties")
Properties props = new Properties()
props.setProperty("app.grails.version", project.grails.grailsVersion)
props.setProperty("app.name", project.name)
props.setProperty("app.version", version)
props.store(buildInfoFile.newWriter(), null)
}
task buildDevelopmentWar(type: GrailsWarTask, dependsOn: createBuildInfo) {
env = 'development'
outputFile = new File("build/distributions/${project.name}-development-${-> project.version}.war")
}
task buildProductionWar(type: GrailsWarTask, dependsOn: createBuildInfo) {
env = 'production'
outputFile = new File("build/distributions/${project.name}-production-${-> project.version}.war")
}
/*********************************
Release Tasks
*********************************/
import org.jets3t.service.impl.rest.httpclient.RestS3Service
import org.jets3t.service.security.AWSCredentials
import org.jets3t.service.model.S3Object
import org.jets3t.service.model.S3Bucket
class S3UploadReleaseTask extends DefaultTask {
@Input
public String awsKey
@Input
public String awsSecretKey
@Input
public String awsBucketName
protected CharSequence input
void setInputFile(CharSequence file) {
this.input = file
}
void setInputFile(File file) {
this.input = file.path
}
@InputFile
File getInputFile() {
return project.file(this.input)
}
@TaskAction
def release() {
println "=== Uploading release to amazon s3 ==="
def credentials = new AWSCredentials(awsKey, awsSecretKey)
def service = new RestS3Service(credentials)
def bucket = new S3Bucket(awsBucketName)
def object = new S3Object(this.getInputFile())
service.putObject(bucket, object)
println "=== Done uploading release to amazon s3 ==="
}
}
class S3DownloadReleaseTask extends DefaultTask {
@Input
public String awsKey
@Input
public String awsSecretKey
@Input
public String awsBucketName
@Input
public String filename
@TaskAction
def download() {
println "=== Downloading ${filename} from amazon s3 ==="
def credentials = new AWSCredentials(awsKey, awsSecretKey)
def service = new RestS3Service(credentials)
def bucket = new S3Bucket(awsBucketName)
def object = service.getObject(bucket, filename)
def file = new File(object.key)
def inputStream = object.getDataInputStream()
def buffer = new byte[1024]
def outputStream = new FileOutputStream(file)
def count = 0
while((count = inputStream.read(buffer)) != -1) {
if(Thread.interrupted() ) {
throw new InterruptedException()
}
outputStream.write(buffer, 0, count)
}
outputStream.close()
inputStream.close()
println "=== Completed downloading ${filename} from amazon s3 ==="
}
}
class S3ListReleasesTask extends DefaultTask {
@Input
public String awsKey
@Input
public String awsSecretKey
@Input
public String awsBucketName
@TaskAction
def list() {
println "=== Listing releases on amazon s3 ==="
def credentials = new AWSCredentials(awsKey, awsSecretKey)
def service = new RestS3Service(credentials)
def bucket = new S3Bucket(awsBucketName)
def objects = service.listObjects(bucket)
objects.each { object ->
println "- ${object.key} (${object.getContentLength()} bytes)"
}
println "=== Done listing releases on amazon s3 ==="
}
}
task releaseProductionWar(type: S3UploadReleaseTask, dependsOn: buildProductionWar) {
awsKey = System.env.AWS_DEPLOY_KEY ?: customAwsDeployKey
awsSecretKey = System.env.AWS_DEPLOY_SECRETKEY ?: customAwsDeploySecret
awsBucketName = System.env.AWS_DEPLOY_BUCKETNAME ?: customAwsDeployBucketName
inputFile = new File("build/distributions/${project.name}-production-${-> project.version}.war")
}
task listReleases(type:S3ListReleasesTask) {
awsKey = System.env.AWS_DEPLOY_KEY ?: customAwsDeployKey
awsSecretKey = System.env.AWS_DEPLOY_SECRETKEY ?: customAwsDeploySecret
awsBucketName = System.env.AWS_DEPLOY_BUCKETNAME ?: customAwsDeployBucketName
}
task downloadRelease(type:S3DownloadReleaseTask) {
doFirst{
filename = key ? key : ""
}
awsKey = System.env.AWS_DEPLOY_KEY ?: customAwsDeployKey
awsSecretKey = System.env.AWS_DEPLOY_SECRETKEY ?: customAwsDeploySecret
awsBucketName = System.env.AWS_DEPLOY_BUCKETNAME ?: customAwsDeployBucketName
}
task tagRelease << {
def tagName = "release-${project.version?.toString()}"
grgit.tag.add(name: tagName, message: "release ${tagName}")
}
/*********************************
Wrapper
*********************************/
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
def jvmOpts = "-Xmx2048m -XX:MaxPermSize=512m"
inputs.property("jvmOpts", jvmOpts)
doLast {
def optsEnvVar = "DEFAULT_JVM_OPTS"
scriptFile.write scriptFile.text.replace("$optsEnvVar=\"\"", "$optsEnvVar=\"$jvmOpts\"")
batchScript.write batchScript.text.replace("set $optsEnvVar=", "set $optsEnvVar=$jvmOpts")
}
}
tasks.withType(org.grails.gradle.plugin.tasks.GrailsTask) { Task t ->
t.jvmOptions {
jvmArgs "-XX:MaxPermSize=512m", "-Xmx2048m", "-Xms512m", "-XX:+CMSClassUnloadingEnabled", "-XX:+HeapDumpOnOutOfMemoryError"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment