mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
250 lines
8.4 KiB
Groovy
250 lines
8.4 KiB
Groovy
buildscript {
|
|
repositories {
|
|
google()
|
|
mavenCentral()
|
|
}
|
|
dependencies {
|
|
classpath 'com.android.tools.build:gradle:7.4.2'
|
|
}
|
|
}
|
|
|
|
allprojects {
|
|
repositories {
|
|
google()
|
|
mavenCentral()
|
|
mavenLocal()
|
|
}
|
|
}
|
|
|
|
ext {
|
|
compileSdkVersion = 34
|
|
minSdkVersion = 14
|
|
targetSdkVersion = 33
|
|
|
|
androidXVersions = [
|
|
activity : '1.8.0-beta01',
|
|
annotation : '1.2.0',
|
|
appCompat : '1.6.1',
|
|
cardView : '1.0.0',
|
|
constraintlayout : '2.0.1',
|
|
coordinatorlayout : '1.1.0',
|
|
core : '1.6.0',
|
|
drawerlayout : '1.1.1',
|
|
experimental : '1.0.0',
|
|
fragment : '1.2.5',
|
|
lifecycle : '2.0.0',
|
|
recyclerView : '1.0.0',
|
|
recyclerViewSelection : '1.0.0',
|
|
resourceInspectionAnnotation : '1.0.1',
|
|
resourceInspectionProcessor : '1.0.1',
|
|
transition : '1.2.0',
|
|
vectorDrawable : '1.1.0',
|
|
viewpager2 : '1.0.0',
|
|
dynamicanimation : '1.0.0',
|
|
]
|
|
|
|
errorproneVersion = '2.15.0'
|
|
testRunnerVersion = '1.4.0'
|
|
espressoVersion = '3.1.0'
|
|
mockitoCoreVersion = '2.25.0'
|
|
truthVersion = '0.45'
|
|
robolectricVersion = '4.9'
|
|
|
|
// Enforce the use of prebuilt dependencies in all sub-projects. This is
|
|
// required for the doclava dependency.
|
|
usePrebuilts = "true"
|
|
|
|
mavenRepoUrl = (project.hasProperty('mavenRepoUrl')
|
|
? project.property('mavenRepoUrl') : '/tmp/myRepo/')
|
|
|
|
// Current version of the library (could be in-development/unreleased).
|
|
mdcLibraryVersion = '1.11.0-alpha02'
|
|
mdcLibraryPackage = "com.google.android.material"
|
|
mdcLibraryDir = "com/google/android/material"
|
|
}
|
|
|
|
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) {
|
|
switch (name) {
|
|
case "activity":
|
|
return "androidx.activity:activity:${androidXVersions.activity}"
|
|
case "annotation":
|
|
return "androidx.annotation:annotation:${androidXVersions.annotation}"
|
|
case "appcompat":
|
|
return "androidx.appcompat:appcompat:${androidXVersions.appCompat}"
|
|
case "cardview":
|
|
return "androidx.cardview:cardview:${androidXVersions.cardView}"
|
|
case "constraintlayout":
|
|
return "androidx.constraintlayout:constraintlayout:${androidXVersions.constraintlayout}"
|
|
case "coordinatorlayout":
|
|
return "androidx.coordinatorlayout:coordinatorlayout:${androidXVersions.coordinatorlayout}"
|
|
case "core":
|
|
return "androidx.core:core:${androidXVersions.core}"
|
|
case "drawerlayout":
|
|
return "androidx.drawerlayout:drawerlayout:${androidXVersions.drawerlayout}"
|
|
case "dynamicanimation":
|
|
return "androidx.dynamicanimation:dynamicanimation:${androidXVersions.dynamicanimation}"
|
|
case "fragment":
|
|
return "androidx.fragment:fragment:${androidXVersions.fragment}"
|
|
case "lifecycleRuntime":
|
|
return "androidx.lifecycle:lifecycle-runtime:${androidXVersions.lifecycle}"
|
|
case "recyclerview":
|
|
return "androidx.recyclerview:recyclerview:${androidXVersions.recyclerView}"
|
|
case "transition":
|
|
return "androidx.transition:transition:${androidXVersions.transition}"
|
|
case "vectordrawable":
|
|
return "androidx.vectordrawable:vectordrawable:${androidXVersions.vectorDrawable}"
|
|
case "recyclerViewSelection":
|
|
return "androidx.recyclerview:recyclerview-selection:${androidXVersions.recyclerViewSelection}"
|
|
case "resourceInspectionAnnotation":
|
|
return "androidx.resourceinspection:resourceinspection-annotation:${androidXVersions.resourceInspectionAnnotation}"
|
|
case "resourceInspectionProcessor":
|
|
return "androidx.resourceinspection:resourceinspection-processor:${androidXVersions.resourceInspectionProcessor}"
|
|
case "viewpager2":
|
|
return "androidx.viewpager2:viewpager2:${androidXVersions.viewpager2}"
|
|
case "experimental":
|
|
return "androidx.annotation:annotation-experimental:${androidXVersions.experimental}"
|
|
default:
|
|
throw new IllegalArgumentException("No mapping exists for name: $name.")
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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 {
|
|
tasks.withType(Test) {
|
|
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
|
|
forkEvery = 80
|
|
maxHeapSize = "2048m"
|
|
minHeapSize = "1024m"
|
|
}
|
|
}
|
|
|
|
subprojects {
|
|
version = rootProject.ext.mdcLibraryVersion
|
|
group = 'com.google.android.material'
|
|
|
|
// Disable strict dependency resolution version constraints for test projects
|
|
if (project.name.contains("tests")) {
|
|
project.configurations.all {
|
|
dependencyConstraints.configureEach { dependencyConstraint ->
|
|
dependencyConstraint.version { versionConstraint ->
|
|
versionConstraint.strictly("")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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) {
|
|
project.android {
|
|
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
|
|
defaultConfig.minSdkVersion rootProject.ext.minSdkVersion
|
|
defaultConfig.targetSdkVersion rootProject.ext.targetSdkVersion
|
|
|
|
// This disables the builds tools automatic vector -> PNG generation
|
|
defaultConfig.generatedDensities = []
|
|
|
|
compileOptions.sourceCompatibility JavaVersion.VERSION_1_8
|
|
compileOptions.targetCompatibility JavaVersion.VERSION_1_8
|
|
|
|
aaptOptions.additionalParameters "--no-version-vectors"
|
|
|
|
android {
|
|
lint {
|
|
checkOnly 'NewApi'
|
|
}
|
|
}
|
|
|
|
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 + "\n"
|
|
}
|
|
|
|
libraryVariants.all {
|
|
it.processJavaResourcesProvider.get().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
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|