blob: d332982a8dacc32e1b61f56bf3276e42b1c0a68b [file] [log] [blame]
Christian Williams6860bf62017-10-31 18:21:46 -07001import org.gradle.plugins.ide.idea.model.IdeaModel
2
Christian Williams6a4bdde2017-10-30 18:52:44 -07003buildscript {
Jonathan Gerrishbd692832018-02-19 11:13:00 -08004 repositories {
5 google()
utzcoz14980872021-03-24 22:17:35 +08006 mavenCentral()
Gautam Korlam32cec502018-04-29 19:00:53 -07007 gradlePluginPortal()
Jonathan Gerrishbd692832018-02-19 11:13:00 -08008 }
Christian Williams6a4bdde2017-10-30 18:52:44 -07009
10 dependencies {
christianwf6623142019-03-08 15:10:39 -080011 gradle
utzcozcc0177b2021-11-03 23:08:09 +080012 classpath 'com.android.tools.build:gradle:7.1.0-beta02'
Al Sutton66ac9c92020-12-31 09:37:33 +000013 classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.3.0'
14 classpath 'com.netflix.nebula:gradle-aggregate-javadocs-plugin:3.0.1'
utzcoz207c22d2021-04-01 00:59:09 +080015 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31"
Al Sutton1b169eb2021-01-23 10:44:15 +000016 classpath "com.github.ben-manes:gradle-versions-plugin:0.36.0"
Christian Williams6a4bdde2017-10-30 18:52:44 -070017 }
18}
19
Christian Williams3ccf2322016-06-20 17:14:58 -070020allprojects {
21 repositories {
Brett Chabot38cada52018-02-21 12:28:51 -080022 google()
Christian Williams9dc1af12018-10-09 16:30:50 -070023 mavenCentral()
utzcoz14980872021-03-24 22:17:35 +080024 gradlePluginPortal()
Christian Williams3ccf2322016-06-20 17:14:58 -070025 }
26
Jared Burrows75ca5782016-07-19 19:51:10 -070027 group = "org.robolectric"
Christian Williams023e43e2017-01-09 12:04:31 -080028 version = thisVersion
Christian Williams3ccf2322016-06-20 17:14:58 -070029}
Christian Williams00b1f7b2017-01-06 18:15:35 -080030
Christian Williams6a4bdde2017-10-30 18:52:44 -070031apply plugin: 'idea'
Al Sutton1b169eb2021-01-23 10:44:15 +000032apply plugin: 'com.github.ben-manes.versions'
Christian Williams00b1f7b2017-01-06 18:15:35 -080033
Christian Williams6860bf62017-10-31 18:21:46 -070034project.ext.configAnnotationProcessing = []
35project.afterEvaluate {
36 def ideaProject = rootProject.extensions.getByType(IdeaModel).project
37 ideaProject.ipr.withXml { provider ->
38 def compilerConfiguration = provider.asNode().component.find { it.'@name' == 'CompilerConfiguration' }
39
40 // prevent compiler from complaining about duplicate classes...
41 def excludeFromCompile = compilerConfiguration.appendNode 'excludeFromCompile'
42 configAnnotationProcessing.each { Project subProject ->
43 excludeFromCompile.appendNode('directory',
44 [url: "file://${subProject.buildDir}/classes/java/main/generated", includeSubdirectories: "true"])
45 }
46
47 // replace existing annotationProcessing tag with a new one...
48 compilerConfiguration.annotationProcessing.replaceNode {
49 annotationProcessing {
50 configAnnotationProcessing.each { Project subProject ->
51 profile(name: "${subProject.name}_main", enabled: "true") {
52 module(name: "${subProject.name}_main")
53 option(name: "org.robolectric.annotation.processing.shadowPackage",
54 value: subProject.shadows.packageName)
55 processor(name: "org.robolectric.annotation.processing.RobolectricProcessor")
56
57 processorPath(useClasspath: "false") {
58 def processorRuntimeCfg = project.project(":processor").configurations['runtime']
59 processorRuntimeCfg.allArtifacts.each { artifact ->
60 entry(name: artifact.file)
61 }
62 processorRuntimeCfg.files.each { file ->
63 entry(name: file)
64 }
65 }
66 }
67 }
68 }
69 }
70 }
71}
72
Christian Williams00b1f7b2017-01-06 18:15:35 -080073apply plugin: 'nebula-aggregate-javadocs'
Christian Williams5209dc62017-04-26 12:01:56 -070074
Christian Williams00b1f7b2017-01-06 18:15:35 -080075rootProject.gradle.projectsEvaluated {
76 rootProject.tasks['aggregateJavadocs'].failOnError = false
77}
Christian Williams0ef6a412017-01-09 18:00:32 -080078
Christian Williams9590ed92019-01-24 19:24:33 -080079gradle.projectsEvaluated {
Christian Williamseeb38e42019-01-25 10:58:18 -080080 def headerHtml = "<ul class=\"navList\" style=\"font-size: 1.5em;\"><li>Robolectric $thisVersion |" +
81 " <a href=\"/\" target=\"_top\">" +
82 "<img src=\"http://robolectric.org/images/logo-with-bubbles-down.png\"" +
83 " style=\"max-height: 18pt; vertical-align: sub;\"/></a></li></ul>"
84 project.allprojects { p ->
85 p.tasks.withType(Javadoc) {
86 options {
87 noTimestamp = true
88 links = [
89 "https://docs.oracle.com/javase/8/docs/api/",
90 "https://developer.android.com/reference/",
91 ]
utzcoz65e67352021-09-30 21:54:22 +080092 // Set javadoc source to JDK 8 to avoid unnamed module problem
93 // when running aggregateJavadoc with OpenJDK 13+.
94 source("8")
Christian Williamseeb38e42019-01-25 10:58:18 -080095 header = headerHtml
96 footer = headerHtml
utzcoz67f56712021-09-30 21:55:17 +080097 // bottom = "<link rel=\"stylesheet\" href=\"http://robolectric.org/assets/css/main.css\">"
Christian Williamseeb38e42019-01-25 10:58:18 -080098 version = thisVersion
99 }
100 }
Christian Williams9590ed92019-01-24 19:24:33 -0800101 }
102}
103
104task aggregateJsondocs(type: Copy) {
Christian Williamse9aec432019-02-06 16:12:45 -0800105 gradle.projectsEvaluated {
106 project.subprojects.findAll { it.plugins.hasPlugin(ShadowsPlugin) }.each { subproject ->
107 dependsOn subproject.tasks["compileJava"]
108 from "${subproject.buildDir}/docs/json"
109 }
Christian Williams9590ed92019-01-24 19:24:33 -0800110 }
111 into "$buildDir/docs/json"
112}
113
114task aggregateDocs {
115 dependsOn ':aggregateJavadocs'
116 dependsOn ':aggregateJsondocs'
117}
118
Christian Williams65b09752019-03-08 14:41:55 -0800119// aggregate test results from all projects...
Christian Williams8e9e0ae2017-04-04 13:35:08 -0700120task aggregateTestReports(type: TestReport) {
121 def jobNumber = System.getenv('TRAVIS_JOB_NUMBER')
122 if (jobNumber == null) {
123 destinationDir = file("$buildDir/reports/allTests")
124 } else {
125 destinationDir = file("$buildDir/reports/allTests/$jobNumber")
126 }
127}
128
Christian Williams65b09752019-03-08 14:41:55 -0800129afterEvaluate {
130 def aggregateTestReportsTask = rootProject.tasks['aggregateTestReports']
131
132 allprojects.each { p ->
133 p.afterEvaluate {
134 p.tasks.withType(Test) { t ->
135 aggregateTestReportsTask.reportOn binResultsDir
136 finalizedBy aggregateTestReportsTask
137 }
138 }
139 }
140}
141
Christian Williams95cf9072017-10-20 17:36:30 -0700142task prefetchSdks() {
Christian Williams95cf9072017-10-20 17:36:30 -0700143 AndroidSdk.ALL_SDKS.each { androidSdk ->
Christian Williams670ba522018-11-29 11:39:29 -0800144 doLast {
Michael Hoisie08853c72021-10-19 15:13:53 -0700145 println("Prefetching ${androidSdk.coordinates}...")
146 // prefetch into maven local repo...
147 def mvnCommand = "mvn -q dependency:get -DrepoUrl=http://maven.google.com \
148 -DgroupId=${androidSdk.groupId} -DartifactId=${androidSdk.artifactId} \
149 -Dversion=${androidSdk.version}"
150 shellExec(mvnCommand)
151
152 // prefetch into gradle local cache...
153 def config = configurations.create("sdk${androidSdk.apiLevel}")
154 dependencies.add("sdk${androidSdk.apiLevel}", androidSdk.coordinates)
155 // causes dependencies to be resolved:
156 config.files
157 }
158 }
159}
160
161task prefetchInstrumentedSdks() {
162 AndroidSdk.ALL_SDKS.each { androidSdk ->
163 doLast {
hoisie765e0752021-02-17 16:39:13 -0800164 println("Prefetching ${androidSdk.preinstrumentedCoordinates}...")
Christian Williams670ba522018-11-29 11:39:29 -0800165 // prefetch into maven local repo...
166 def mvnCommand = "mvn -q dependency:get -DrepoUrl=http://maven.google.com \
hoisie765e0752021-02-17 16:39:13 -0800167 -DgroupId=${androidSdk.groupId} -DartifactId=${androidSdk.preinstrumentedArtifactId} \
168 -Dversion=${androidSdk.preinstrumentedVersion}"
Christian Williams670ba522018-11-29 11:39:29 -0800169 shellExec(mvnCommand)
170
171 // prefetch into gradle local cache...
172 def config = configurations.create("sdk${androidSdk.apiLevel}")
hoisie765e0752021-02-17 16:39:13 -0800173 dependencies.add("sdk${androidSdk.apiLevel}", androidSdk.preinstrumentedCoordinates)
Christian Williams670ba522018-11-29 11:39:29 -0800174 // causes dependencies to be resolved:
175 config.files
176 }
Christian Williams95cf9072017-10-20 17:36:30 -0700177 }
Christian Williams95cf9072017-10-20 17:36:30 -0700178}
179
Christian Williams670ba522018-11-29 11:39:29 -0800180private void shellExec(String mvnCommand) {
181 def process = mvnCommand.execute()
182 def out = new StringBuffer()
183 def err = new StringBuffer()
184 process.consumeProcessOutput(out, err)
185 process.waitFor()
186 if (out.size() > 0) println out
187 if (err.size() > 0) println err
188 if (process.exitValue() != 0) System.exit(1)
189}
190
Christian Williams5c708402017-11-01 09:33:11 -0700191task prefetchDependencies() {
Christian Williams5c708402017-11-01 09:33:11 -0700192 doLast {
193 allprojects.each { p ->
Gautam Korlam32cec502018-04-29 19:00:53 -0700194 p.configurations.each { config ->
195 // causes dependencies to be resolved:
196 if (config.isCanBeResolved()) {
christianwf6623142019-03-08 15:10:39 -0800197 try {
198 config.files
utzcoz659ddd92021-02-15 23:00:07 +0800199 } catch (ResolveException e) {
utzcoz4dd66112021-05-26 21:23:48 +0800200 // ignore resolution issues for integration tests and test app, sigh
201 if (!p.path.startsWith(":integration_tests:")
202 && !p.path.startsWith(":testapp")) {
christianwf6623142019-03-08 15:10:39 -0800203 throw e
204 }
205 }
Christian Williams5c708402017-11-01 09:33:11 -0700206 }
207 }
208 }
209 }
Christian Williams95cf9072017-10-20 17:36:30 -0700210}
211
Christian Williams0ef6a412017-01-09 18:00:32 -0800212// for use of external initialization scripts...
Christian Williams814382f2017-01-11 15:35:10 -0800213project.ext.allSdks = AndroidSdk.ALL_SDKS