Skip to content

COLA Gradle Plugin

Bruno Santos edited this page Jul 23, 2015 · 2 revisions

Non-incremental Usage

buildscript {
    repositories {
        mavenLocal()
    }

    dependencies {
        classpath group: 'com.github.bmsantos', name: 'cola-tests', version: '0.4.0'
        classpath group: 'com.github.bmsantos', name: 'cola-gradle-plugin', version: '0.4.0'
    }
}

dependencies {
    // testCompile 'org.slf4j:slf4j-simple:1.7.7' // Optional - Can use other slf4j bridge.
    testCompile 'com.github.bmsantos:cola-tests:0.4.0'
    testCompile 'junit:junit:4.+'
}

apply plugin: 'cola'
cola {
    targetDirectory = compileTestJava.destinationDir
    includes = ['org/gradle/cola/tests/**'] 
    excludes = ['something/else/**', 'and/some/CompiledFile.class']
}
colac.dependsOn testClasses
colac.mustRunAfter testClasses

test {
    useJUnit()
    dependsOn colac
}

See example here

Incremental Usage

apply plugin: 'java'
compileJava {
    options.incremental = true
}

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        classpath 'com.github.bmsantos:cola-tests:0.4.0'
        classpath 'com.github.bmsantos:cola-gradle-plugin:0.4.0'
    }
}

dependencies {
    compile 'commons-collections:commons-collections:3.2'
    // testCompile 'org.slf4j:slf4j-simple:1.7.7' // Optional - Can use other slf4j bridge.
    testCompile 'com.github.bmsantos:cola-tests:0.4.0'
    testCompile 'junit:junit:4.+'
}

apply plugin: 'cola'
cola {
    includes = ['org/gradle/cola/tests/**'] 
    excludes = ['something/else/**', 'and/some/CompiledFile.class']
}
icolac.inputDir = file(compileTestJava.destinationDir)
icolac.destinationDir = file("${project.buildDir}/colac")
icolac.dependsOn testClasses
icolac.mustRunAfter testClasses

task(fixTestClassPath) << {
    // Fix test task classpath (this should be done automatically by the test task
    // since the destinationDir is modified through configuration.
    def cp = sourceSets.test.runtimeClasspath
    def filteredCp = files(test.testClassesDir).plus(cp.filter() { f -> !f.equals(icolac.inputDir) })
    sourceSets.test.runtimeClasspath = filteredCp
}
fixTestClassPath.mustRunAfter icolac

test {
    useJUnit()
    dependsOn icolac
    dependsOn fixTestClassPath
    testClassesDir = icolac.destinationDir
}

See example here