| import com.android.build.gradle.LibraryExtension |
| |
| class VersionFileWriterTask extends DefaultTask { |
| static final String RESOURCE_DIRECTORY = "generatedResources" |
| static final VERSION_FILE_PATH = RESOURCE_DIRECTORY + "/META-INF/%s_%s.version" |
| @Input |
| String version |
| @OutputFile |
| File outputFile |
| |
| @TaskAction |
| void write() { |
| outputFile.write(version) |
| } |
| |
| /** |
| * Sets up Android Library project to have a task that generates a version file. |
| * It must be called after [LibraryExtension] has been resolved. |
| * |
| * @param project an Android Library project. |
| */ |
| static void setUpAndroidLibrary(Project project, LibraryExtension library) { |
| def group = project.properties["group"] as String |
| def artifactId = project.properties["name"] as String |
| def version = project.properties["version"] as String |
| |
| // Add a java resource file to the library jar for version tracking purposes. |
| def artifactName = new File( |
| project.buildDir, |
| String.format(VERSION_FILE_PATH, group, artifactId)) |
| |
| def writeVersionFile = project.tasks.create("writeVersionFile", |
| VersionFileWriterTask.class) |
| writeVersionFile.version = version |
| writeVersionFile.outputFile = artifactName |
| |
| if (library != null) { |
| library.libraryVariants.all { |
| it.processJavaResources.dependsOn(writeVersionFile) |
| } |
| |
| library.sourceSets.getByName("main").resources.srcDir( |
| new File(project.buildDir, RESOURCE_DIRECTORY) |
| ) |
| } |
| } |
| } |
| |
| buildscript { |
| Properties databindingProperties = new Properties() |
| databindingProperties.load(new FileInputStream("$projectDir/../databinding.properties")) |
| Properties buildToolsProperties = new Properties() |
| buildToolsProperties.load(new FileInputStream("$projectDir/../../buildSrc/base/version.properties")) |
| Properties dependencyProperties = new Properties() |
| dependencyProperties.load(new FileInputStream("$projectDir/../../buildSrc/base/dependencies.properties")) |
| |
| def runningInIde = project.hasProperty('android.injected.invoked.from.ide') |
| // this is done by bazel but if we are in IDE it also configures so we need to distinguish |
| def autoConfigured = !gradle.startParameter.getInitScripts().isEmpty() && !runningInIde |
| ext.autoConfigured = autoConfigured |
| |
| def TOOLS_VERSION = |
| System.getenv("VERSION") ?: buildToolsProperties.get("buildVersion").toString() |
| def OUT_REPO = System.getenv("OUT_REPO") ?: System.getenv("BUILD_DIR") |
| def MAVEN_REPO = System.getenv("MAVEN_REPO") |
| def PREBUILTS_REPO = System.getenv("PREBUILTS_REPO") |
| if (runningInIde) { |
| Properties devVersions = new Properties() |
| devVersions.load(new FileInputStream("$projectDir/../../buildSrc/base/version.properties")) |
| // invoked in the IDE, go w/ defaults. |
| TOOLS_VERSION = devVersions.buildVersion |
| if (TOOLS_VERSION .contains('-')) { |
| TOOLS_VERSION = TOOLS_VERSION .substring(0, TOOLS_VERSION.indexOf('-')) + "-dev" |
| } |
| MAVEN_REPO = MAVEN_REPO ?: "${projectDir}/../../../out/repo" |
| OUT_REPO = OUT_REPO ?: "${projectDir}/../../../out/repo" |
| PREBUILTS_REPO = PREBUILTS_REPO ?: "${projectDir}/../../../prebuilts/tools/common/m2/repository" |
| } else if (autoConfigured) { |
| if (TOOLS_VERSION == null || OUT_REPO == null) { |
| throw new GradleException("""must set the following env variables: |
| VERSION:$TOOLS_VERSION // tools build version |
| OUT_REPO:$OUT_REPO // maven repo to upload artifacts""") |
| } |
| } else if (TOOLS_VERSION == null |
| || MAVEN_REPO == null |
| || OUT_REPO == null |
| || PREBUILTS_REPO == null) { |
| throw new GradleException("""must set the following env variables: |
| VERSION:$TOOLS_VERSION // tools build version |
| MAVEN_REPO:$MAVEN_REPO // maven repo for ToT tools build |
| OUT_REPO:$OUT_REPO // maven repo to upload artifacts |
| PREBUILTS_REPO:$PREBUILTS_REPO // prebuilts repo to fix support library dependencies""") |
| } |
| |
| databindingProperties.version = TOOLS_VERSION |
| databindingProperties.androidPluginVersion = TOOLS_VERSION |
| databindingProperties.compileSdkVersion = databindingProperties.compileSdkVersionStr.trim() |
| databindingProperties.group = "androidx.databinding" |
| databindingProperties.maven = [:] |
| if (autoConfigured) { |
| // bazel build |
| databindingProperties.maven.out_repo = new File(OUT_REPO, "local_repo").getAbsolutePath() |
| databindingProperties.maven.zip_out = new File(OUT_REPO, "local_repo_zip") |
| } else { |
| // gradle build |
| databindingProperties.maven.out_repo = new File(OUT_REPO).getAbsolutePath() |
| databindingProperties.maven.tools_repo = file(MAVEN_REPO).getAbsolutePath() |
| databindingProperties.maven.prebuilts_repo = file(PREBUILTS_REPO).getAbsolutePath() |
| } |
| ext.dataBindingConfig = databindingProperties |
| def supportLibVersion = "1.0.0" |
| def lifecycleVersion = "2.4.0" |
| ext.libs = [:] |
| ext.libs.android_support_annotations = "androidx.annotation:annotation:$supportLibVersion" |
| ext.libs.android_support_collection = "androidx.collection:collection:$supportLibVersion" |
| ext.libs.android_support_cardview_v7 = "androidx.cardview:cardview:$supportLibVersion" |
| ext.libs.android_support_appcompat_v7 = "androidx.appcompat:appcompat:$supportLibVersion" |
| ext.libs.fragments = "androidx.fragment:fragment:1.2.0" |
| // some of these lifecycle deps are unnecessary but we are keeping them to stay backwards |
| // compatible with the lifecycle-extensions dependency |
| ext.libs.lifecycle_livedata = "androidx.lifecycle:lifecycle-livedata:$lifecycleVersion" |
| ext.libs.lifecycle_process = "androidx.lifecycle:lifecycle-process:$lifecycleVersion" |
| ext.libs.lifecycle_service = "androidx.lifecycle:lifecycle-service:$lifecycleVersion" |
| ext.libs.lifecycle_viewmodel = "androidx.lifecycle:lifecycle-viewmodel:$lifecycleVersion" |
| ext.libs.android_arch_lifecycle_runtime = "androidx.lifecycle:lifecycle-runtime:$lifecycleVersion" |
| ext.libs.android_arch_lifecycle_runtime_ktx = "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion" |
| ext.libs.kotlin_gradle_plugin = dependencyProperties.kotlin_gradle_plugin |
| ext.libs.kotlin_stdlib = dependencyProperties.kotlin_stdlib |
| ext.libs.coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1" |
| |
| dependencies { |
| classpath "com.android.tools.build:gradle:$TOOLS_VERSION" |
| classpath rootProject.ext.libs.kotlin_gradle_plugin |
| } |
| |
| if (!autoConfigured) { |
| repositories { |
| maven { |
| url = dataBindingConfig.maven.tools_repo |
| } |
| maven { |
| url = dataBindingConfig.maven.prebuilts_repo |
| } |
| } |
| } |
| } |
| |
| task createArchive(type: Zip) { |
| description "Creates a maven repository that includes just the libraries compiled in this" + |
| " project, without any history from prebuilts." |
| from dataBindingConfig.maven.out_repo |
| if (dataBindingConfig.maven.zip_out != null) { |
| destinationDirectory.set(dataBindingConfig.maven.zip_out) |
| } |
| archiveBaseName.set("dataBindingRuntimeRepo") |
| } |
| |
| subprojects { |
| def BUILD_DIR = System.getenv("BUILD_DIR") |
| if (BUILD_DIR != null) { |
| buildDir = new File(BUILD_DIR, "$name-build") |
| } |
| if (project.path == ":doclava") { |
| return |
| } |
| apply plugin: 'maven-publish' |
| group = dataBindingConfig.group |
| version = dataBindingConfig.version |
| if (!autoConfigured) { |
| repositories { |
| maven { |
| url = dataBindingConfig.maven.tools_repo |
| } |
| maven { |
| url = dataBindingConfig.maven.prebuilts_repo |
| } |
| } |
| } |
| |
| publishing { |
| repositories { |
| maven { |
| url = "${dataBindingConfig.maven.out_repo}" |
| } |
| } |
| } |
| createArchive.dependsOn tasks.named('publish') |
| configurations.all { |
| resolutionStrategy { |
| failOnVersionConflict() |
| |
| preferProjectModules() |
| force 'androidx.lifecycle:lifecycle-viewmodel:2.4.0' |
| force 'androidx.lifecycle:lifecycle-livedata-core:2.4.0' |
| force 'androidx.fragment:fragment:1.0.0' |
| } |
| } |
| project.afterEvaluate { |
| VersionFileWriterTask.setUpAndroidLibrary(project, |
| project.extensions.findByType(LibraryExtension.class)) |
| } |
| } |
| |
| // creates the javadoc task for all of data binding runtime libraries |
| def getRootDocsTask(p) { |
| def rootDocs = rootProject.tasks.findByName("generateDocs") |
| if (rootDocs != null) { |
| return rootDocs |
| } |
| rootDocs = p.rootProject.tasks.create(name : "generateDocs",type: Javadoc, dependsOn: p.configurations.doclava) { |
| def docDir = "javadoc-offline" |
| if (project.hasProperty("online")) { |
| docDir = "javadoc-online" |
| options.addStringOption("dac_libraryroot", "android/databinding") |
| options.addStringOption("dac_dataname", "DATABINDING_DATA") |
| options.addStringOption("toroot", "/") |
| options.addStringOption("hdf", "dac") |
| options.addBooleanOption("yamlV2", true) |
| options.addBooleanOption("devsite", true) |
| } |
| title = null |
| def sdkVersion = dataBindingConfig.compileSdkVersionInt |
| destinationDir = new File(buildDir, docDir) |
| // add baseLibrary sources, not pretty but easy solution. |
| source = files('../baseLibrary/src/main/java') |
| classpath = files("${rootDir}/../../../prebuilts/sdk/${sdkVersion}/public/android.jar") |
| options.addStringOption "federate Android", "http://developer.android.com" |
| options.addStringOption "federationapi Android", |
| "${rootDir}/../../../prebuilts/sdk/${sdkVersion}/public/api/android.txt" |
| options.encoding = "UTF-8" |
| options.doclet = "com.google.doclava.Doclava" |
| options.docletpath = p.configurations.getByName("doclava").resolve().toList() |
| options.addStringOption("templatedir", "${rootDir}/../../../external/doclava/res/assets/templates-sdk/") |
| exclude '**/BuildConfig.java' |
| exclude '**/R.java' |
| } |
| } |
| |
| def enableDoclava(p) { |
| p.configurations { |
| doclava |
| } |
| |
| p.dependencies { |
| doclava project(':doclava') |
| } |
| |
| def docsTask = getRootDocsTask(p) |
| p.afterEvaluate { |
| p.android.libraryVariants.all { variant -> |
| def name = variant.buildType.name |
| |
| if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) { |
| return // Skip debug builds. |
| } |
| docsTask.classpath += p.files(variant.javaCompile.classpath) + |
| p.files(variant.javaCompile.destinationDir) |
| docsTask.source += files(p.android.sourceSets.main.java.srcDirs) |
| docsTask.dependsOn variant.javaCompile |
| } |
| } |
| |
| } |
| |
| if (findProject(":doclava") != null) { |
| subprojects { p -> |
| if (p.path != ":doclava") { |
| project.plugins.whenPluginAdded { plugin -> |
| def isAndroidLibrary = "com.android.build.gradle.LibraryPlugin".equals(plugin.class.name) |
| if (isAndroidLibrary) { |
| enableDoclava(p) |
| } |
| } |
| } |
| } |
| } |
| |