blob: d933b55206e0e9d90d74cc9ca663a4251d3e6872 [file] [log] [blame]
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.android.build.api.artifact.MultipleArtifact;
import com.android.build.api.artifact.ScopedArtifact;
import com.android.build.api.variant.ScopedArtifacts;
import java.util.jar.*;
import java.util.regex.*;
// Top-level build file where you can add dataBindingConfiguration options common to all sub-projects/modules.
apply plugin: 'com.android.library'
android {
namespace "com.android.databinding.library"
compileSdkVersion dataBindingConfig.compileSdkVersion
buildToolsVersion dataBindingConfig.buildToolsVersion
defaultConfig {
minSdkVersion 14
targetSdkVersion dataBindingConfig.targetSdkVersion
versionCode 1
versionName "1.0"
consumerProguardFiles 'proguard-rules.txt'
}
compileOptions {
sourceCompatibility dataBindingConfig.javaTargetCompatibility
targetCompatibility dataBindingConfig.javaSourceCompatibility
}
buildTypes {
release {
minifyEnabled false
}
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'android/databinding/DataBinderMapperImpl.class'
}
buildTypes.all {
consumerProguardFiles 'proguard-consumer-rules.pro'
}
androidComponents {
onVariants(selector().all(), { variant ->
TaskProvider<ExcludeShimsTask> taskProvider = project.tasks.register(
variant.getName() + "ExcludeShimsTask", ExcludeShimsTask.class
)
variant.artifacts
.forScope(ScopedArtifacts.Scope.PROJECT)
.use(taskProvider)
.toTransform(
ScopedArtifact.CLASSES.INSTANCE,
{ it.getAllJars() },
{ it.getAllDirectories() },
{ it.getOutput() }
)
taskProvider.configure { task ->
task.excludes.add("android/databinding/DataBindingComponent.*")
task.excludes.add("android/databinding/DataBinderMapperImpl.*")
}
})
}
publishing {
singleVariant("release")
}
}
dependencies {
implementation rootProject.ext.libs.android_support_core_utils
implementation "com.android.databinding:baseLibrary:${dataBindingConfig.version}"
api project(':viewbinding')
compileOnly rootProject.ext.libs.android_arch_lifecycle_extensions
api rootProject.ext.libs.android_arch_lifecycle_runtime
}
//create jar tasks
android.libraryVariants.all { variant ->
def name = variant.buildType.name
if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) {
return // Skip debug builds.
}
def suffix = name.capitalize()
def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
}
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
artifactId = 'library'
from components.release
artifact project.tasks.named("sourceJarRelease")
pom {
licenses {
license {
name = dataBindingConfig.licenseName
url = dataBindingConfig.licenseUrl
distribution = dataBindingConfig.licenseDistribution
}
}
}
}
}
}
}
/**
* Remove shim classes that will be generated by the application annotation processor.
*/
abstract class ExcludeShimsTask extends Jar {
@InputFiles
abstract ListProperty<RegularFile> getAllJars();
@InputFiles
abstract ListProperty<Directory> getAllDirectories();
@OutputFiles
abstract RegularFileProperty getOutput();
@Input
Set<String> excludes = new HashSet<String>();
@TaskAction
void taskAction() {
OutputStream jarOutput = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(
output.get().getAsFile()
)))
Set<Pattern> patterns = excludes.collect {
Pattern.compile(it)
}
allJars.get().forEach { file ->
JarFile jarFile = new JarFile(file.asFile)
for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) {
JarEntry jarEntry = e.nextElement();
if (!shouldIgnore(patterns, jarEntry.name)) {
jarOutput.putNextEntry(new JarEntry(jarEntry.name))
jarFile.getInputStream(jarEntry).withCloseable {
jarOutput << it
}
jarOutput.closeEntry()
}
}
jarFile.close()
}
allDirectories.get().forEach { directory ->
directory.asFile.traverse(type: groovy.io.FileType.FILES) { file ->
String relativePath = directory.asFile.toURI().relativize(file.toURI()).getPath()
.replace(File.separatorChar, '/' as char)
if (!shouldIgnore(patterns, relativePath)) {
jarOutput.putNextEntry(new JarEntry(relativePath))
new FileInputStream(file).withCloseable { inputStream ->
jarOutput << inputStream
}
jarOutput.closeEntry()
}
}
}
jarOutput.close()
}
boolean shouldIgnore(Collection<Pattern> patterns, String entryName) {
for (pattern in patterns) {
if (pattern.matcher(entryName).matches()) {
return true
}
}
return false
}
}
task prebuildAar(type : Copy) {
dependsOn tasks.named("publish")
from "$buildDir/outputs/aar/library-release.aar"
into dataBindingConfig.prebuildFolder
rename { String fileName ->
"databinding-library.aar"
}
}