普通文本  |  71行  |  1.72 KB

apply plugin: 'java'

configurations {
    // similar to 'default', export compile-time dependencies
    host.extendsFrom(hostCompile)
    target.extendsFrom(targetCompile)
}

sourceSets {
    host {
        java {
            srcDirs = ['src/main/java']
        }
    }

    target {
        java {
            srcDirs = ['src/main/java']
            include 'org/**',
                    'junit/extensions/**',
                    // remove these packages since they are in android.test.runner
                    // and proguard complains if they are present
                    // 'junit/runner/**',
                    // 'junit/textui/**',
                    'junit/framework/ComparisonCompactor.java',
                    'junit/framework/JUnit4TestAdapterCache.java',
                    'junit/framework/JUnit4TestAdapter.java',
                    'junit/framework/JUnit4TestCaseFacade.java'
        }
    }
}

task targetJar(type: Jar) {
    from sourceSets.target.output
    dependsOn targetClasses
    baseName "junit4"
    classifier "target"
}

task hostJar(type: Jar) {
    from sourceSets.host.output
    dependsOn hostClasses
    baseName "junit4"
    classifier "host"
}

artifacts {
    host hostJar
    target targetJar
}

if (project.hasProperty("usePrebuilts") && project.usePrebuilts == "true") {
    repositories {
        maven { url '../../prebuilts/tools/common/m2/repository' }
    }

    dependencies {
        targetCompile getAndroidPrebuilt('4')
        targetCompile 'org.hamcrest:hamcrest-core:1.1'

        hostCompile 'org.hamcrest:hamcrest-core:1.1'
    }
} else {
    dependencies {
        targetCompile getAndroidPrebuilt('4')
        targetCompile project(':hamcrest')

        hostCompile project(':hamcrest')
    }
}