blob: 3d52e7254d8f1508f15e4c62bff645e6fcd6da05 [file] [log] [blame]
/*
* Copyright 2021 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 androidx.build.LibraryGroups
import androidx.build.LibraryVersions
import androidx.build.Publish
import androidx.build.RunApiTasks
import androidx.build.dependencies.DependenciesKt
import androidx.build.shadow.AndroidXDontIncludeResourceTransformer
plugins {
id("AndroidXPlugin")
id("java-library")
id("com.google.protobuf")
id("com.github.johnrengelman.shadow")
}
configurations {
shadowed
compileOnly.extendsFrom(shadowed)
testCompile.extendsFrom(shadowed)
}
dependencies {
implementation("androidx.annotation:annotation:1.1.0")
shadowed(libs.protobufLite)
}
sourceSets {
main.java.srcDirs += "$buildDir/generated/source/proto"
}
// HACK: Move standard JAR to have another suffix and build a shadowJar with
// no classifier (so it's picked up as the primary artifact).
jar {
archiveClassifier = 'before-shadow'
}
shadowJar {
archiveClassifier = ''
configurations = [project.configurations.shadowed]
relocate "com.google.protobuf", "androidx.wear.tiles.protobuf"
// libs.protobufLite ships with a standard set of proto files in the JAR, which clash if this
// library is included from two different downstream libraries. exclude("*.proto") (or
// **/*.proto etc etc) doesn't exclude the ones from libs.protobufLite, so take a more heavy handed
// approach and use a transformer to strip those files.
// TODO: move back to DontIncludeResourceTransformer.class once Shadow plugin version >6.1.0
transform(AndroidXDontIncludeResourceTransformer.class) {
resource = ".proto"
}
}
assemble.dependsOn(shadowJar)
configurations {
apiElements.outgoing.artifacts.clear()
apiElements.outgoing.artifact(shadowJar) {
builtBy shadowJar
}
runtimeElements.outgoing.artifacts.clear()
runtimeElements.outgoing.artifact(shadowJar) {
builtBy shadowJar
}
}
protobuf {
protoc {
artifact = DependenciesKt.getDependencyAsString(libs.protobufCompiler)
}
// Generates the java proto-lite code for the protos in this project. See
// https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
// for more information.
generateProtoTasks {
all().each { task ->
project.tasks.named("sourceJar").configure {
it.dependsOn(task)
}
project.tasks.named("runErrorProne").configure {
it.dependsOn(task)
}
project.tasks.named("lint").configure {
it.dependsOn(task)
it.enabled = false
}
project.tasks.named("lintAnalyze").configure {
it.dependsOn(task)
it.enabled = false
}
task.builtins {
java {
option 'lite'
}
}
}
}
}
androidx {
name = "Wear Tiles Proto"
publish = Publish.SNAPSHOT_AND_RELEASE
mavenGroup = LibraryGroups.WEAR_TILES
inceptionYear = "2020"
description = "Jarjar the generated proto and proto-lite dependency for use by " +
"wear-tiles."
runApiTasks = new RunApiTasks.No("Metalava doesn't properly parse the proto sources " +
"(b/180579063)")
}