普通文本  |  110行  |  3.68 KB

import org.gradle.plugins.ide.idea.model.IdeaModel

buildscript {
    repositories { jcenter() }

    dependencies {
        classpath 'com.netflix.nebula:gradle-aggregate-javadocs-plugin:2.2.+'
        classpath 'ch.raffael.pegdown-doclet:pegdown-doclet:1.3'
    }
}

plugins {
    id "net.ltgt.apt" version "0.13" // automatic annotation processing
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
    }

    group = "org.robolectric"
    version = thisVersion
}

apply plugin: 'idea'
apply plugin: 'net.ltgt.apt'

project.ext.configAnnotationProcessing = []
project.afterEvaluate {
    def ideaProject = rootProject.extensions.getByType(IdeaModel).project
    ideaProject.ipr.withXml { provider ->
        def compilerConfiguration = provider.asNode().component.find { it.'@name' == 'CompilerConfiguration' }

        // prevent compiler from complaining about duplicate classes...
        def excludeFromCompile = compilerConfiguration.appendNode 'excludeFromCompile'
        configAnnotationProcessing.each { Project subProject ->
            excludeFromCompile.appendNode('directory',
                    [url: "file://${subProject.buildDir}/classes/java/main/generated", includeSubdirectories: "true"])
        }

        // replace existing annotationProcessing tag with a new one...
        compilerConfiguration.annotationProcessing.replaceNode {
            annotationProcessing {
                configAnnotationProcessing.each { Project subProject ->
                    profile(name: "${subProject.name}_main", enabled: "true") {
                        module(name: "${subProject.name}_main")
                        option(name: "org.robolectric.annotation.processing.shadowPackage",
                                value: subProject.shadows.packageName)
                        processor(name: "org.robolectric.annotation.processing.RobolectricProcessor")

                        processorPath(useClasspath: "false") {
                            def processorRuntimeCfg = project.project(":processor").configurations['runtime']
                            processorRuntimeCfg.allArtifacts.each { artifact ->
                                entry(name: artifact.file)
                            }
                            processorRuntimeCfg.files.each { file ->
                                entry(name: file)
                            }
                        }
                    }
                }
            }
        }
    }
}

apply plugin: 'nebula-aggregate-javadocs'
apply plugin: 'ch.raffael.pegdown-doclet'

rootProject.gradle.projectsEvaluated {
    rootProject.tasks['aggregateJavadocs'].failOnError = false
}

task aggregateTestReports(type: TestReport) {
    def jobNumber = System.getenv('TRAVIS_JOB_NUMBER')
    if (jobNumber == null) {
        destinationDir = file("$buildDir/reports/allTests")
    } else {
        destinationDir = file("$buildDir/reports/allTests/$jobNumber")
    }
}

task prefetchSdks() {
    AndroidSdk.ALL_SDKS.each { androidSdk ->
        def config = configurations.create("sdk${androidSdk.apiLevel}")
        dependencies.add("sdk${androidSdk.apiLevel}", androidSdk.coordinates)
        // causes dependencies to be resolved:
        config.files
    }
}

task prefetchDependencies() {
    dependsOn "prefetchSdks"

    doLast {
        allprojects.each { p ->
            ['compile', 'runtime', 'testCompile', 'testRuntime'].each { configName ->
                if (p.configurations.findByName(configName)) {
                    // causes dependencies to be resolved:
                    p.configurations[configName].files
                }
            }
        }
    }
}

// for use of external initialization scripts...
project.ext.allSdks = AndroidSdk.ALL_SDKS