forked from robolectric/robolectric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
191 lines (169 loc) · 6.85 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import org.gradle.plugins.ide.idea.model.IdeaModel
buildscript {
apply from: 'dependencies.gradle'
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
gradle
classpath libs.android.gradle
classpath libs.error.prone.gradle
classpath libs.aggregate.javadocs.gradle
classpath libs.kotlin.gradle
classpath libs.spotless.gradle
}
}
allprojects {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
group = "org.robolectric"
version = thisVersion
}
apply plugin: 'idea'
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'
rootProject.gradle.projectsEvaluated {
rootProject.tasks['aggregateJavadocs'].failOnError = false
}
gradle.projectsEvaluated {
def headerHtml = "<ul class=\"navList\" style=\"font-size: 1.5em;\"><li>Robolectric $thisVersion |" +
" <a href=\"/\" target=\"_top\">" +
"<img src=\"http://robolectric.org/images/logo-with-bubbles-down.png\"" +
" style=\"max-height: 18pt; vertical-align: sub;\"/></a></li></ul>"
project.allprojects { p ->
p.tasks.withType(Javadoc) {
options {
noTimestamp = true
links = [
"https://docs.oracle.com/javase/8/docs/api/",
"https://developer.android.com/reference/",
]
// Set javadoc source to JDK 8 to avoid unnamed module problem
// when running aggregateJavadoc with OpenJDK 13+.
source("8")
header = headerHtml
footer = headerHtml
// bottom = "<link rel=\"stylesheet\" href=\"http://robolectric.org/assets/css/main.css\">"
version = thisVersion
}
}
}
}
gradle.projectsEvaluated {
tasks.register('aggregateJsondocs', Copy) {
project.subprojects.findAll { it.plugins.hasPlugin(ShadowsPlugin) }.each { subproject ->
dependsOn subproject.tasks["compileJava"]
from "${subproject.buildDir}/docs/json"
}
into "$buildDir/docs/json"
}
}
tasks.register('aggregateDocs') {
dependsOn ':aggregateJavadocs'
dependsOn ':aggregateJsondocs'
}
tasks.register('prefetchSdks') {
AndroidSdk.ALL_SDKS.each { androidSdk ->
doLast {
println("Prefetching ${androidSdk.coordinates}...")
// prefetch into maven local repo...
def mvnCommand = "mvn -q dependency:get -DrepoUrl=http://maven.google.com \
-DgroupId=${androidSdk.groupId} -DartifactId=${androidSdk.artifactId} \
-Dversion=${androidSdk.version}"
shellExec(mvnCommand)
// prefetch into gradle local cache...
def config = configurations.create("sdk${androidSdk.apiLevel}")
dependencies.add("sdk${androidSdk.apiLevel}", androidSdk.coordinates)
// causes dependencies to be resolved:
config.files
}
}
}
tasks.register('prefetchInstrumentedSdks') {
AndroidSdk.ALL_SDKS.each { androidSdk ->
doLast {
println("Prefetching ${androidSdk.preinstrumentedCoordinates}...")
// prefetch into maven local repo...
def mvnCommand = "mvn -q dependency:get -DrepoUrl=http://maven.google.com \
-DgroupId=${androidSdk.groupId} -DartifactId=${androidSdk.preinstrumentedArtifactId} \
-Dversion=${androidSdk.preinstrumentedVersion}"
shellExec(mvnCommand)
// prefetch into gradle local cache...
def config = configurations.create("sdk${androidSdk.apiLevel}")
dependencies.add("sdk${androidSdk.apiLevel}", androidSdk.preinstrumentedCoordinates)
// causes dependencies to be resolved:
config.files
}
}
}
private void shellExec(String mvnCommand) {
def process = mvnCommand.execute()
def out = new StringBuffer()
def err = new StringBuffer()
process.consumeProcessOutput(out, err)
process.waitFor()
if (out.size() > 0) println out
if (err.size() > 0) println err
if (process.exitValue() != 0) System.exit(1)
}
tasks.register('prefetchDependencies') {
doLast {
allprojects.each { p ->
p.configurations.each { config ->
// causes dependencies to be resolved:
if (config.isCanBeResolved()) {
try {
config.files
} catch (ResolveException e) {
// ignore resolution issues for integration tests and test app, sigh
if (!p.path.startsWith(":integration_tests:")
&& !p.path.startsWith(":testapp")) {
throw e
}
}
}
}
}
}
}
// for use of external initialization scripts...
project.ext.allSdks = AndroidSdk.ALL_SDKS