mirror of
https://github.com/material-components/material-components-android.git
synced 2026-01-19 19:41:35 +08:00
267 lines
8.5 KiB
Groovy
267 lines
8.5 KiB
Groovy
buildscript {
|
|
repositories {
|
|
google()
|
|
jcenter()
|
|
}
|
|
dependencies {
|
|
classpath 'com.android.tools.build:gradle:3.0.1'
|
|
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
|
|
}
|
|
}
|
|
|
|
allprojects {
|
|
repositories {
|
|
google()
|
|
jcenter()
|
|
mavenLocal()
|
|
}
|
|
}
|
|
|
|
ext {
|
|
compileSdkVersion = 'android-P'
|
|
minSdkVersion = 14
|
|
targetSdkVersion = 27
|
|
supportVersion = '28.0.0-alpha1'
|
|
|
|
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/')
|
|
mdcLibraryVersion = '28.0.0-alpha1'
|
|
mdcLibraryPackage = "android.support.design"
|
|
mdcLibraryDir = "android/support/design"
|
|
}
|
|
|
|
// lint every library
|
|
task(lint) << {
|
|
}
|
|
|
|
// TODO: setup docs build and API txt generation
|
|
|
|
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 'design'
|
|
}
|
|
def pathComponents = name.tokenize('/')
|
|
def knownComponents = ['lib', 'java', 'android', 'support', 'design']
|
|
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 = 'design'
|
|
for (def i = firstUnknownComponent; i < pathComponents.size(); i++) {
|
|
result = result + '-' + pathComponents[i];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
subprojects {
|
|
version = rootProject.ext.supportVersion
|
|
group = 'com.android.support'
|
|
|
|
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 'Android Design Support Library'
|
|
description 'The Android Design Support Library 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'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|