alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (build.gradle)

This example Groovy source code file (build.gradle) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

antlr, antlr, ensure, ensure, file, file, meta-inf/services, meta-inf/services, wrapper

The Groovy build.gradle source code

apply plugin: 'groovy'
apply plugin: 'code-quality'

group = 'org.codehaus.groovy'
version = groovyVersion

sourceCompatibility = 1.5
targetCompatibility = 1.5

buildDir = 'target'

repositories {
    // todo Some repos are needed only for some configs. Declare them just for the configuration once Gradle allows this.
    mavenRepo urls: ["http://repo1.maven.org/maven2"] // default, tools
    mavenRepo urls: ["http://www.aQute.biz/repo"] // examples
    mavenRepo urls: ["http://repository.jboss.org/maven2"] // examples, tools
}

// todo do we need compile and runtime scope for examples?
configurations {
    tools
    examplesCompile.extendsFrom compile
    examplesRuntime.extendsFrom examplesCompile
    antlr
}

dependencies {
//    groovy files('/home/hd/tmp/groovy-all.jar') // files(sourceSets.main.classesDir)
    groovy files("$buildDir/classes")
    groovy "asm:asm:3.2"
    groovy "antlr:antlr:2.7.7"
    groovy "asm:asm-commons:3.2"
    groovy "asm:asm-util:3.2"
    groovy "asm:asm-analysis:3.2"
    groovy "asm:asm-tree:3.2"

    compile("bsf:bsf:2.4.0") {
        exclude(group: 'commons-logging', module: 'commons-logging')
    }
    compile "junit:junit:4.8.2"
    compile "commons-cli:commons-cli:1.2"
    compile "org.apache.ant:ant:1.8.2"
    compile "javax.servlet:servlet-api:2.4"
    compile "javax.servlet:jsp-api:2.0"
    compile("com.thoughtworks.xstream:xstream:1.3.1") {
        exclude(group: 'xpp3', module: 'xpp3_min')
    }
    compile("jline:jline:0.9.94") {
        exclude(group: 'junit', module: 'junit')
    }
    compile "org.fusesource.jansi:jansi:1.6"
    compile("org.apache.ivy:ivy:2.2.0") {
        transitive = false
    }
    runtime "org.apache.ant:ant-junit:1.8.2"
    runtime "org.apache.ant:ant-launcher:1.8.2"
    runtime "org.apache.ant:ant-antlr:1.8.2"
    runtime("commons-logging:commons-logging:1.1.1") {
        exclude(group: 'log4j', module: 'log4j')
        exclude(group: 'logkit', module: 'logkit')
        exclude(group: 'avalon-framework', module: 'avalon-framework')
    }
    testCompile "jmock:jmock:1.2.0"
    testCompile "jmock:jmock-cglib:1.2.0"
    testCompile "xmlunit:xmlunit:1.3"
    testCompile "hsqldb:hsqldb:1.8.0.10"
    testCompile "ch.qos.logback:logback-classic:0.9.21"
    testCompile "log4j:log4j:1.2.16"
    testCompile "org.slf4j:jcl-over-slf4j:1.6.0"
    testCompile "com.thoughtworks.qdox:qdox:1.12"
    testCompile "org.apache.ant:ant-testutil:1.8.2"
    runtime "org.codehaus.gpars:gpars:0.11"
    runtime "org.coconut.forkjoin:jsr166y:070108"

    // todo this was provided
    compile "org.livetribe:livetribe-jsr223:2.0.6"

    tools "com.google.code:jarjar:1.1"
    tools("checkstyle:checkstyle:4.4") {
        exclude(module: 'junit')
    }
    tools "redhill:simian:2.2.4"
    tools("net.sourceforge.cobertura:cobertura:1.9.4.1") {
        exclude(module: 'asm')
        exclude(module: 'asm')
        exclude(module: 'ant')
    }
    tools "asm:asm:3.2"
    tools "com.thoughtworks.qdox:qdox:1.12"
    tools "biz.aQute:bnd:0.0.401"

    examplesCompile "lucene:lucene:1.4.3"
    examplesCompile "org.eclipse:osgi:3.5.0.v20090520"
    examplesRuntime("commons-httpclient:commons-httpclient:3.1") {
        exclude(module: 'junit')
        exclude(module: 'commons-logging')
        exclude(module: 'commons-codec')
    }
    examplesRuntime("openejb:openejb-loader:1.0") {
        exclude(module: 'log4j')
        exclude(module: 'openejb-core')
        exclude(module: 'geronimo-jta_1.0.1B_spec')
        exclude(module: 'geronimo-servlet_2.4_spec')
        exclude(module: 'geronimo-ejb_2.1_spec')
        exclude(module: 'geronimo-j2ee-connector_1.5_spec')
    }

    antlr "org.apache.ant:ant-antlr:1.8.2"
}

sourceSets {
    main {
        java {
            srcDirs = ["$projectDir/src/main"]
            fileTree("$projectDir/src/main/groovy/ui").matching {
                exclude 'GroovyMain.java', 'GroovySocketServer.java'
            }.visit {details ->
                exclude "groovy/ui/$details.path"
            }
        }
        groovy {
            srcDirs = ["$projectDir/src/main"]
        }
        resources {
            srcDirs = ["$projectDir/src/main", "$projectDir/src/tools"]
            include "META-INF/services/*", "META-INF/groovy-release-info.properties",
                    "groovy/grape/*.xml", "groovy/ui/*.properties", "groovy/ui/**/*.png",
                    "groovy/inspect/swingui/AstBrowserProperties.groovy",
                    "org/codehaus/groovy/tools/shell/**/*.properties",
                    "org/codehaus/groovy/tools/shell/**/*.xml",
                    "org/codehaus/groovy/antlib.xml",
                    "org/codehaus/groovy/tools/groovydoc/gstringTemplates/**/*.*",
                    "org/codehaus/groovy/tools/groovy.ico"
        }
        classesDir = "$buildDir/classes" as File
    }
    test {
        groovy {
            srcDirs = ["$projectDir/src/test"]
            if (!isJava16()) {
                exclude "groovy/**/vm6/*Test.groovy"
                exclude "org/codehaus/groovy/**/vm6/*Test.groovy"
            }
        }
        classesDir = "$buildDir/test-classes" as File
    }
    tools {
        groovy {
            srcDirs = ["$projectDir/src/tools"]
        }
        resources {
            srcDirs = ["$projectDir/src/tools"]
        }
        compileClasspath = configurations.tools + sourceSets.main.runtimeClasspath
        runtimeClasspath = classes + compileClasspath
        classesDir = "$buildDir/tools-classes" as File
    }
    examples {
        groovy {
            srcDirs = ["$projectDir/src/examples"]
        }
        resources {
            srcDirs = ["$projectDir/src/examples"]
        }
        compileClasspath = configurations.examplesRuntime + sourceSets.main.classes
        classesDir = "$buildDir/examples-classes" as File
    }
}

// remove this from config once GRADLE-854 is fixed.
processResources.doLast {
    copy {
        from("$projectDir/src/main") {
            include "groovy/inspect/swingui/AstBrowserProperties.groovy",
                    "org/codehaus/groovy/tools/groovydoc/gstringTemplates/GroovyDocTemplateInfo.java"
        }
        into sourceSets.main.classesDir
    }
}

task ensureGrammars {
    description = "Ensure all the Antlr generated files are up to date."
    antlrDirectory = "$projectDir/src/main/org/codehaus/groovy/antlr"
    groovyParserDirectory = "$antlrDirectory/parser"
    javaParserDirectory = "$antlrDirectory/java"
    doFirst {
        ant {
            taskdef(name: 'antlr',
                    classname: 'org.apache.tools.ant.taskdefs.optional.ANTLR',
                    classpath: configurations.antlr.asPath)

            mkdir dir: groovyParserDirectory
            antlr(target: "$antlrDirectory/groovy.g", outputdirectory: groovyParserDirectory) {
                classpath path: configurations.compile.asPath
            }
            antlr(target: "$javaParserDirectory/java.g", outputdirectory: javaParserDirectory) {
                classpath path: configurations.compile.asPath
            }
        }
    }
}

compileJava {
    dependsOn ensureGrammars
    doLast {
        mkdir "$sourceSets.main.classesDir/META-INF"
        ant {
            java(classname: "org.codehaus.groovy.tools.DgmConverter",
                    fork: "true",
                    failonerror: "true",
                    outputproperty: 'outy',
                    errorproperty: 'errr',
                    classpath: sourceSets.main.runtimeClasspath.asPath) 
        }
//        println "Out: " + ant.properties.outy
//        println "Err: " + ant.properties.errr
    }
}


compileGroovy {
    groovyOptions.fork(memoryMaximumSize: groovycMain_mx)
}

compileTestGroovy {
    groovyOptions.fork(memoryMaximumSize: groovycTest_mx)
}

compileExamplesGroovy {
    groovyOptions.fork(memoryMaximumSize: groovycExamples_mx)
}

def isJava16() {
    System.properties['java.version'].contains('1.6')
}

// suppress CheckStyle
task checkstyleExamples(overwrite: true) << {};
task checkstyleMain(overwrite: true) << {};
task checkstyleTest(overwrite: true) << {};
task checkstyleTools(overwrite: true) << {};

codeNarcConfigFileName = "./config/codenarc/codenarc.groovy"

// ignore CodeNarc on examples
task codenarcExamples(overwrite: true) << {};
// don't fail build on CodeNarc tasks
tasks.withType(CodeNarc).all { codeNarcTask ->
    codeNarcTask.ignoreFailures = true
}

// provide to other build scripts
isJava6 = this.&isJava16()

apply from: "$projectDir/gradle/test.gradle"
apply from: "$projectDir/gradle/docs.gradle"
apply from: "$projectDir/gradle/assemble.gradle"
apply from: "$projectDir/gradle/upload.gradle"

task wrapper(type: Wrapper) {
    gradleVersion = '0.9.2'
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy build.gradle source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.