blob: a761edc19e7ae698360c4187f5fa41d5922cfcbc [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.LibraryType
import androidx.build.Publish
import androidx.build.RunApiTasks
import com.github.jengelman.gradle.plugins.shadow.transformers.DontIncludeResourceTransformer
plugins {
id("AndroidXPlugin")
id("kotlin")
id("com.google.protobuf")
id("com.github.johnrengelman.shadow")
}
configurations {
shadowed
compileOnly.extendsFrom(shadowed)
testCompile.extendsFrom(shadowed)
}
dependencies {
api(libs.kotlinStdlib)
implementation("androidx.datastore:datastore-core:1.0.0")
shadowed(libs.protobufLite)
}
// 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.glance.appwidget.proto"
// 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.
transform(DontIncludeResourceTransformer.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 = libs.protobufCompiler.get()
}
// 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 ->
task.builtins {
java {
option 'lite'
}
}
}
}
}
androidx {
name = "Glance AppWidget Protos"
type = LibraryType.PUBLISHED_LIBRARY
mavenGroup = LibraryGroups.GLANCE
inceptionYear = "2021"
runApiTasks = new RunApiTasks.No("No public API required for internal use with app widgets.")
description = "Protos for use with glance app widgets."
}
// Kotlin 1.5.31 would provide a different set of attributes on some of the variants, which,
// possibly due to a coincidence, could sometimes nudge Gradle variant-aware dependency resolution
// to choosing one of the variants as the best match, while also making it silently choose not the
// variant that we wanted it to match in other cases.
// It isn't clear to me if the old (1.5.31) is more correct, or if the new behavior (1.6.0)
// highlighting a potential ambiguity is more correct. Presumably the later (so no tracking bug?),
// but I made Jetbrains aware and I think they might take a look to investigate further.
configurations.getByName("shadowRuntimeElements").canBeConsumed = false