kendricku cd3f114a3f [Release] Updated minSdkVersion to 23.
PiperOrigin-RevId: 845841935
2025-12-18 15:24:52 +00:00

346 lines
11 KiB
Groovy

import javax.inject.Inject
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
version = mdcLibraryVersion
dependencies {
api libs.androidx.activity
api libs.androidx.annotation
api libs.androidx.annotation.experimental
api libs.androidx.appcompat
api libs.androidx.cardview
api libs.androidx.coordinatorlayout
api libs.androidx.constraintlayout
api libs.androidx.core
api libs.androidx.customview
api libs.androidx.drawerlayout
api libs.androidx.dynamicanimation
api libs.androidx.fragment
api libs.androidx.lifecycle.runtime
api libs.androidx.recyclerview
api libs.androidx.resourceinspection.annotation
api libs.androidx.transition
api libs.androidx.vectordrawable
api libs.androidx.viewpager2
api libs.androidx.graphics.shapes
annotationProcessor libs.androidx.resourceinspection.processor
// Align kotlin versions
implementation(platform(libs.kotlin.bom))
implementation libs.errorprone.annotations
testImplementation libs.androidx.test.core
testImplementation libs.androidx.test.runner
testImplementation libs.junit
testImplementation libs.truth
testImplementation libs.mockito.core
testImplementation libs.robolectric
}
def srcDirs = [
'com/google/android/material/animation',
'com/google/android/material/appbar',
'com/google/android/material/badge',
'com/google/android/material/behavior',
'com/google/android/material/bottomappbar',
'com/google/android/material/bottomnavigation',
'com/google/android/material/bottomsheet',
'com/google/android/material/button',
'com/google/android/material/canvas',
'com/google/android/material/card',
'com/google/android/material/carousel',
'com/google/android/material/checkbox',
'com/google/android/material/chip',
'com/google/android/material/circularreveal',
'com/google/android/material/circularreveal/cardview',
'com/google/android/material/circularreveal/coordinatorlayout',
'com/google/android/material/color',
'com/google/android/material/datepicker',
'com/google/android/material/dialog',
'com/google/android/material/divider',
'com/google/android/material/dockedtoolbar',
'com/google/android/material/drawable',
'com/google/android/material/elevation',
'com/google/android/material/expandable',
'com/google/android/material/floatingactionbutton',
'com/google/android/material/floatingtoolbar',
'com/google/android/material/imageview',
'com/google/android/material/internal',
'com/google/android/material/loadingindicator',
'com/google/android/material/listitem',
'com/google/android/material/materialswitch',
'com/google/android/material/math',
'com/google/android/material/menu',
'com/google/android/material/motion',
'com/google/android/material/navigation',
'com/google/android/material/navigationrail',
'com/google/android/material/overflow',
'com/google/android/material/progressindicator',
'com/google/android/material/radiobutton',
'com/google/android/material/resources',
'com/google/android/material/ripple',
'com/google/android/material/search',
'com/google/android/material/shape',
'com/google/android/material/shadow',
'com/google/android/material/sidesheet',
'com/google/android/material/slider',
'com/google/android/material/snackbar',
'com/google/android/material/stateful',
'com/google/android/material/switchmaterial',
'com/google/android/material/tabs',
'com/google/android/material/textfield',
'com/google/android/material/textview',
'com/google/android/material/theme',
'com/google/android/material/theme/overlay',
'com/google/android/material/timepicker',
'com/google/android/material/tooltip',
'com/google/android/material/transition',
'com/google/android/material/transformation',
'com/google/android/material/typography',
]
android {
namespace "com.google.android.material"
sourceSets {
main.manifest.srcFile 'java/com/google/android/material/AndroidManifest.xml'
main.java.srcDir 'java'
main.java.includes = srcDirs.collect { it + '/**/*.java' }
main.java.excludes = [
'**/build/**',
]
srcDirs.forEach {
main.res.srcDirs += 'java/' + it + '/res'
main.res.srcDirs += 'java/' + it + '/res-public'
test.res.srcDirs += 'javatests/' + it + '/res'
}
test.java.srcDir 'javatests'
}
testOptions.unitTests.includeAndroidResources = true
buildTypes.all {
consumerProguardFiles 'proguard-behaviors.pro', 'proguard-inflater.pro'
}
defaultConfig {
minSdkVersion 23
}
publishing {
singleVariant("release")
}
}
task getVersion {
doLast {
println version
}
}
task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
from(android.sourceSets.main.java.srcDirs) {
// Needed because we have Java sources and resources in same directory
include '**/*.java'
includeEmptyDirs = false
}
}
publishing {
repositories {
maven {
url = "$mavenRepoUrl"
}
}
publications {
release(MavenPublication) {
artifact androidSourcesJar
groupId = 'com.google.android.material'
artifactId = 'material'
version project.version
pom {
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 23 or later.'
url = 'https://github.com/material-components/material-components-android'
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'
}
}
afterEvaluate {
from components.release
}
}
}
}
/**
* Generate library documentation.
*
* This task requires a Dackka jar to be run. This can be passed to the task
* by running the task from the command line and setting the --dackkaJar
* option.
*
* Example: ./gradlew generateDocumentation --dackkaJar="<path/to/dackka.jar>"
*
* The resulting documentation will be placed in `lib/build/docs` and contain
* documentation for both java and kotlin clients.
*
* TODO: b/149338266 - Dackka does not support links to resources in documentation.
* TODO: b/396171398 - inheritDoc results hav formatting issues with Dackka.
*/
tasks.register("generateDocumentation", DackkaRunner) {
group = "Publishing"
description = "Generate javadocs using dackka"
version = mdcLibraryVersion
config = layout.buildDirectory.file("resources/dackka_config.json").get().asFile
outputDirectory = layout.buildDirectory.dir("docs").get()
// Add all the files from the main source set to be documented by dackka
sourceDirectories.setFrom(
android.sourceSets.main.java.srcDirs.absolutePath
)
dependenciesClasspath.setFrom(
files("${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"),
)
}
/**
* A task that uses Dackka to generate javadoc.
*/
abstract class DackkaRunner extends DefaultTask {
private String dackkaJar;
/**
* Set the path to the Dackka jar to use by setting the --dackkaJar command
* line argument when running the gradle task used by this task.
*
* @param path the path to the dackka jar
*/
@Option(option = "dackkaJar", description = "path to daccka jar")
void setDackkaJar(String path) {
this.dackkaJar = path
}
@Input
String getDackkaJar() {
return dackkaJar;
}
/**
* The Material library version of these docs.
*
* This should most likely match mdcLibraryVersion from the projects build
* file.
*/
@Input
String version;
/** Source directories to be documented. */
@InputFiles
final ConfigurableFileCollection sourceDirectories = project.files()
@InputFiles
final ConfigurableFileCollection dependenciesClasspath = project.files();
/** A file that should be populated with the Dackka configuration. */
@OutputFile
abstract File config;
/** The output containing documentation generated by Dackka. */
@OutputDirectory
abstract Directory outputDirectory;
@Inject
abstract ExecOperations getExecOperations()
@TaskAction
void run() {
// Delete any previously generated documentation
outputDirectory.asFile.deleteDir()
// Populate the Dackka config json file with Material-specific properties
writeDackkaConfig()
// Run the Dackka jar and generate docs
getExecOperations().javaexec {
classpath(dackkaJar)
args(config.absolutePath)
}
}
/** Populate the Dackka config file with project specific values. */
private void writeDackkaConfig() {
def configContents = """
{
"modeuleName": "Material Components",
"moduleVersion": "$version",
"outputDir": "${outputDirectory.asFile.absolutePath}",
"offlineMode": "true",
"noJdkLink": "true",
"sourceSets": [
{
"moduleDisplayName": "lib",
"analysisPlatform": "jvm",
"externalDocumentationLinks": [],
"sourceSetID": {
"scopeId": "com",
"sourceSetName": "main"
},
"sourceRoots": [${sourceDirectories.collect { '"' + it.absolutePath + '"' }.join(", ")}],
"samples": [],
"includes": [],
"classpath": [${dependenciesClasspath.collect { '"' + it.absolutePath + '"'}.join(", ")}],
"sourceLinks": [],
"documentedVisibilities": ["PUBLIC", "PROTECTED"]
}
],
"pluginsConfiguration": [
{
"fqPluginName": "com.google.devsite.DevsitePlugin",
"serializationFormat": "JSON",
"values": "${getDevsitePluginConfigValues()}"
}
]
}
""".trim();
config.write(configContents)
}
/** Returns the Dackka Devsite plugin configuration json string. */
private String getDevsitePluginConfigValues() {
return """
{
"docRootPath": "reference",
"projectPath": "com/google/android/material",
"excludedPackages": [ ".*excluded.*" ],
"javaDocsPath": "",
"kotlinDocsPath": "kotlin",
"baseSourceLink": "https://github.com/material-components/material-components-android/blob/${version}/lib/java/%s",
"annotationsNotToDisplay": [ "java.lang.Override", "kotlin.ParameterName" ]
}
""".trim().replace("\n", "").replace('"', '\\\"')
}
}