forked from material-components/material-components-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
266 lines (232 loc) · 8.49 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
}
allprojects {
repositories {
google()
jcenter()
mavenLocal()
}
}
ext {
compileSdkVersion = 28
minSdkVersion = 14
targetSdkVersion = 27
supportVersion = '28.0.0'
testRunnerVersion = '1.0.0'
espressoVersion = '3.0.0'
// Enforce the use of prebuilt dependencies in all sub-projects. This is
// required for the doclava dependency.
usePrebuilts = "true"
// Disable pre-dexing when gradle called with -PdisablePreDex;
preDexLibs = !project.hasProperty('disablePreDex')
mavenRepoUrl = (project.hasProperty('mavenRepoUrl')
? project.property('mavenRepoUrl') : 'file://localhost/tmp/myRepo/')
// Current version of the library (could be in-development/unreleased).
mdcLibraryVersion = '1.1.0-alpha01'
mdcLibraryPackage = "com.google.android.material"
mdcLibraryDir = "com/google/android/material"
}
// lint every library
task(lint) << {
}
task clean(type: Delete) {
delete rootProject.buildDir
}
private def getTransformedProjectPath(projectPath) {
def pathComponents = projectPath.tokenize('/')
def result = ''
def currentPath = ''
pathComponents.each { component ->
if (currentPath == '') {
currentPath += component
} else {
currentPath += '-' + component
}
result += ':' + currentPath
}
return result
}
/**
* Return the module dependency for the given compatibility library name.
*
*/
def compatibility(name) {
def lib
switch (name) {
case "annotations":
lib = "com.android.support:support-annotations"
break
case "compat":
lib = "com.android.support:support-compat"
break
case "core_ui":
lib = "com.android.support:support-core-ui"
break
case "core_utils":
lib = "com.android.support:support-core-utils"
break
case "fragment":
lib = "com.android.support:support-fragment"
break
case "transition":
lib = "com.android.support:transition"
break
case "v7/appcompat":
lib = "com.android.support:appcompat-v7"
break
case "v7/cardview":
lib = "com.android.support:cardview-v7"
break
case "v7/recyclerview":
lib = "com.android.support:recyclerview-v7"
break
default:
throw new IllegalArgumentException("No mapping exists for name: $name.")
}
return "$lib:${project.rootProject.ext.supportVersion}"
}
/**
* Return the project dependency for the given project path.
*
*/
def fromPath(path) {
return getTransformedProjectPath(path)
}
def getArchivesBaseName(name) {
if (name == 'lib') {
return 'material'
}
def pathComponents = name.tokenize('-')
def knownComponents = ['lib', 'java', 'com', 'google', 'android', 'material']
def firstUnknownComponent = knownComponents.size();
for (def i = 0; i < knownComponents.size() && i < pathComponents.size(); i++) {
if (pathComponents[i] != knownComponents[i]) {
firstUnknownComponent = i;
break;
}
}
def result = 'material'
for (def i = firstUnknownComponent; i < pathComponents.size(); i++) {
result = result + '-' + pathComponents[i];
}
return result;
}
subprojects {
version = rootProject.ext.supportVersion
group = 'com.google.android.material'
project.plugins.whenPluginAdded { plugin ->
def isAndroidLibrary = "com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)
def isAndroidApp = "com.android.build.gradle.AppPlugin".equals(plugin.class.name)
def isAndroidTest = "com.android.build.gradle.TestPlugin".equals(plugin.class.name)
if (isAndroidLibrary || isAndroidApp) {
// Enable code coverage for debug builds only if we are not running inside the IDE,
// since enabling coverage reports breaks the method parameter resolution in the IDE
// debugger. Note that we avoid doing this for Android Test projects as it causes
// crashes on Dalvik ('Class ref in pre-verified class resolved to unexpected implementation')
project.android.buildTypes.debug.testCoverageEnabled = !hasProperty('android.injected.invoked.from.ide')
}
if (isAndroidLibrary || isAndroidApp || isAndroidTest) {
if (!isAndroidTest) {
// Enforce NewApi lint check as fatal.
project.android.lintOptions.check 'NewApi'
project.android.lintOptions.fatal 'NewApi'
// Output lint errors on stdout
project.android.lintOptions.textReport true
project.android.lintOptions.textOutput 'stdout'
rootProject.lint.dependsOn project.lint
}
// Disable pre-dexing when gradle called with -PdisablePreDex;
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
project.android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig.minSdkVersion rootProject.ext.minSdkVersion
// This disables the builds tools automatic vector -> PNG generation
defaultConfig.generatedDensities = []
compileOptions.sourceCompatibility JavaVersion.VERSION_1_7
compileOptions.targetCompatibility JavaVersion.VERSION_1_7
aaptOptions.additionalParameters "--no-version-vectors"
if (isAndroidLibrary) {
def JAVA_RESOURCES_TEMP_DIR = "$buildDir/javaResources"
task writeVersionFile() {
def versionFileDir = JAVA_RESOURCES_TEMP_DIR + '/META-INF'
def versionFileName = mdcLibraryPackage + '_' + getArchivesBaseName(project.name) + '.version'
new File(versionFileDir).mkdirs()
new File(versionFileDir + '/' + versionFileName).text = mdcLibraryVersion
}
libraryVariants.all {
it.processJavaResources.dependsOn(writeVersionFile)
}
project.android.sourceSets.main.resources.srcDir JAVA_RESOURCES_TEMP_DIR
}
}
if (isAndroidLibrary) {
project.afterEvaluate {
project.tasks.all({
if (it instanceof com.android.build.gradle.tasks.GenerateBuildConfig) {
// Disable generating BuildConfig.java
it.enabled = false
}
})
project.android {
task sourcesJar(type: Jar) {
classifier = 'sources'
from(android.sourceSets.main.java.srcDirs) {
// Needed because we have Java sources and resources in same directory
include '**/*.java'
includeEmptyDirs = false
}
}
artifacts {
archives sourcesJar
}
}
if (project.uploadArchives.repositories.hasProperty("mavenDeployer")) {
project.uploadArchives.repositories.mavenDeployer.pom {
project {
name 'Material Components for Android'
description 'Material Components for Android is a static library that you can add to your Android application in order to use APIs that provide implementations of the Material Design specification. Compatible on devices running API 14 or later.'
url 'http://developer.android.com/tools/extras/support-library.html'
inceptionYear '2015'
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 {
connection 'scm:git:https://github.com/material-components/material-components-android.git'
url 'https://github.com/material-components/material-components-android'
}
}
// Adds a <type> tag for each dependency. This assumes that all dependencies except
// for support-annotations are aars, but it can break if in the future we depend on
// anything else that's not an aar.
// TODO: Remove this once Gradle automatically determines dependency types.
whenConfigured { pom ->
pom.dependencies.findAll { dependency ->
if (dependency.artifactId != 'support-annotations') {
dependency.type = 'aar'
}
}
}
}
}
}
}
}
}
}