forked from android/android-ktx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
233 lines (195 loc) · 6.77 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import com.android.build.gradle.api.BaseVariant
buildscript {
ext.versions = [
'kotlin': '1.2.21',
'supportLibrary': '27.0.2',
'atsl': '1.0.1',
]
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-beta1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.15"
}
}
group = 'androidx.core'
version = '0.2-SNAPSHOT'
apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'org.jetbrains.dokka-android'
apply plugin: 'maven'
repositories {
jcenter()
google()
}
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 14
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
checkTestSources true
}
// TODO replace with https://issuetracker.google.com/issues/72050365 once released.
libraryVariants.all {
it.generateBuildConfig.enabled = false
}
}
configurations {
ktlint
metalava
}
dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}"
implementation "com.android.support:support-annotations:${versions.supportLibrary}"
implementation "com.android.support:support-compat:${versions.supportLibrary}"
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation "com.android.support:support-annotations:${versions.supportLibrary}"
androidTestImplementation "com.android.support.test:runner:${versions.atsl}"
androidTestImplementation "com.android.support.test:rules:${versions.atsl}"
androidTestImplementation 'com.google.truth:truth:0.39'
androidTestImplementation 'com.squareup.okio:okio:1.13.0'
ktlint 'com.github.shyiko:ktlint:0.15.0'
// Metalava isn't released yet. Check in its jar and explicitly track its transitive deps.
metalava files('metalava.jar')
metalava 'com.android.tools.external.org-jetbrains:uast:26.1.0-beta1'
metalava 'com.android.tools.external.com-intellij:intellij-core:26.1.0-beta1'
metalava 'com.android.tools.lint:lint-api:26.1.0-beta1'
metalava 'com.android.tools.lint:lint-checks:26.1.0-beta1'
metalava 'com.android.tools.lint:lint-gradle:26.1.0-beta1'
metalava 'com.android.tools.lint:lint:26.1.0-beta1'
metalava 'org.jetbrains.kotlin:kotlin-stdlib:1.2.21'
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
freeCompilerArgs = ['-Xno-param-assertions']
}
}
task ktlint(type: JavaExec, group: LifecycleBasePlugin.VERIFICATION_GROUP) {
inputs.dir('src')
outputs.dir('src')
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = 'com.github.shyiko.ktlint.Main'
args '--android', 'src/**/*.kt'
}
check.dependsOn ktlint
task ktFormat(type: JavaExec, group: 'formatting') {
inputs.dir('src')
outputs.dir('src')
description = 'Fix Kotlin code style deviations.'
classpath = configurations.ktlint
main = 'com.github.shyiko.ktlint.Main'
args '--android', '-F', 'src/**/*.kt'
}
def variantClasspath(BaseVariant variant) {
return (android.bootClasspath + variant.compileConfiguration.incoming.artifactView { config ->
config.attributes { container ->
container.attribute(Attribute.of("artifactType", String.class), "jar")
}
}.artifacts.artifacts.collect { it.file }).join(File.pathSeparator)
}
android.libraryVariants.all { variant ->
// TODO eliminate variants https://issuetracker.google.com/issues/62201427
if (variant.buildType.isDebuggable()) {
return
}
task updateApi(type: JavaExec) {
inputs.dir('src/main/java')
outputs.file('api/current.txt')
classpath = configurations.metalava
main = 'com.android.tools.metalava.Driver'
doFirst {
args = [
'--no-banner',
'--source-path', 'src/main/java',
'--compatible-output=no',
'--omit-common-packages=yes',
'--output-kotlin-nulls=yes',
'--hide', 'HiddenSuperclass',
'--classpath', variantClasspath(variant),
'--api', 'api/current.txt'
]
}
}
task checkApi(type: JavaExec) {
inputs.file('api/current.txt')
inputs.dir('src/main/java')
outputs.file('api/current.txt')
classpath = configurations.metalava
main = 'com.android.tools.metalava.Driver'
doFirst {
args = [
'--no-banner',
'--source-path', 'src/main/java',
'--compatible-output=no',
'--omit-common-packages=yes',
'--output-kotlin-nulls=yes',
'--input-kotlin-nulls=yes',
'--hide', 'HiddenSuperclass',
'--classpath', variantClasspath(variant),
'--check-compatibility',
'--previous-api', 'api/current.txt'
]
}
}
check.dependsOn checkApi
}
dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/documentation"
}
task dokkaJar(type: Jar, dependsOn: dokka) {
classifier = 'javadoc'
from dokka.outputDirectory
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
}
artifacts {
archives dokkaJar
archives sourcesJar
}
def googleRepo = "$buildDir/google-repo"
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://$googleRepo")
pom.project {
name "Android KTX Core"
description "A set of Kotlin extensions for Android app development."
url "https://github.com/android/android-ktx"
inceptionYear 2017
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
name "The Android Open Source Project"
}
}
scm {
url "https://github.com/android/android-ktx"
connection "scm:git:git://github.com/android/android-ktx.git"
}
}
}
}
}
task deleteGoogleRepo(type: Delete) {
delete googleRepo
}
uploadArchives.dependsOn(deleteGoogleRepo)
task googleZip(type: Zip, dependsOn: uploadArchives) {
from googleRepo
}
assemble.dependsOn(googleZip)