buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "commons-io:commons-io:1.4"
    }
}

apply id: 'groovy'

version = '1.3.6'

sourceCompatibility = "1.5"
targetCompatibility = "1.5"
archivesBaseName = 'grails'

configurations {
    compile.transitive = true
    jsp21.extendsFrom compile
}

dependencies {
    lib = "$projectDir/lib"
    groovy files(fileTree(dir: lib as File, includes: ['groovy-all-1.7.*.jar']))
    compile files(fileTree(dir: lib as File, includes: ['*.jar'], excludes: ['jsp-api-2.1.jar', 'groovy-all-1.7.5.jar']), "${System.getenv('JAVA_HOME')}/lib/tools.jar")
    jsp21 files("$lib/jsp-api-2.1.jar")
}

sourceSets {
    main {
        java {
            srcDirs = []
        }
        groovy {
            srcDirs = ['src/java']
        }
        resources {
            srcDirs = ['src/java']
            include '**/*.properties', '**/*.xsd', '**/*.dtd'
        }
    }
    jsp21 {
        compileClasspath = files(configurations.jsp21, main.classes)
        groovy.srcDirs = ['src/jsp21']
        resources.srcDirs = []
    }
    test {
        java {
            srcDirs = []
        }
        groovy {
            srcDirs = ['src/test']
        }
        resources {
            srcDirs = ['src/test', 'src/jar']
            exclude '**/*.java', '**/*.groovy'
        }
    }
    buildScripts {
        compileClasspath = sourceSets.main.compileClasspath + main.classes
        classesDir = "$buildDir/compiled-scripts" as File
        groovy.srcDirs = ['scripts']
        resources.srcDirs = []
    }
}

jsp21Classes.dependsOn classes
task allClasses(dependsOn: [classes, jsp21Classes, buildScriptsClasses])

configure([compileGroovy, compileTestGroovy]) {
    groovyOptions.fork(memoryInitialSize: '128M', memoryMaximumSize: '1G')
    groovyOptions.encoding = "UTF-8"
}

configure([compileJava, compileTestJava]) {
    options.deprecation = true
    options.debug = true
}

apply {
    url 'gradle/docs.gradle'
    url 'gradle/assemble.gradle'
    url 'gradle/unit-test.gradle'
    url 'gradle/maven.gradle'
    url 'gradle/findbugs.gradle'
}

clean {
    // add additional dirs
    from(docs.destinationDir, libs.destinationDir)
}

task wrapper(type: Wrapper) {
    gradleVersion = '0.9-20100118091626+0100'
    jarPath = 'gradle/wrapper'
}
