Files
RIBs/android/build.gradle

203 lines
7.2 KiB
Groovy

/*
* Copyright (C) 2017. Uber Technologies
*
* 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 net.ltgt.gradle.errorprone.CheckSeverity
apply from: 'gradle/dependencies.gradle'
buildscript {
apply from: rootProject.file('gradle/dependencies.gradle')
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath deps.build.gradlePlugins.android
classpath deps.build.gradlePlugins.errorprone
classpath deps.build.gradlePlugins.kotlin
classpath deps.build.gradlePlugins.spotless
classpath deps.build.gradlePlugins.gradleMavenPublish
}
}
Set<String> useErrorProneProjects = [
"memory-leaks",
"tutorial1",
"tutorial2"
]
def moduleFriends = [
'rib-android': 'rib-base',
'rib-debug-utils': 'rib-base',
'rib-router-navigator': 'rib-base',
'rib-test': 'rib-base',
'rib-workflow-test': 'rib-workflow',
'rib-coroutines-test': 'rib-coroutines'
]
subprojects {
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
repositories {
google()
mavenCentral()
}
apply plugin: 'com.diffplug.spotless'
spotless {
format 'misc', {
target '**/*.md', '**/.gitignore'
trimTrailingWhitespace()
endWithNewline()
}
kotlin {
target "**/*.kt"
ktlint(deps.versions.ktlint).userData(['indent_size': '2', 'continuation_indent_size' : '4'])
// TODO: enable when ktfmt depends on google-java-format < v1.8
// ktfmt(deps.versions.ktfmt)
licenseHeaderFile rootProject.file('config/spotless/copyright.kt')
trimTrailingWhitespace()
endWithNewline()
}
java {
target "src/*/java/**/*.java"
googleJavaFormat(deps.versions.gjf)
licenseHeaderFile rootProject.file('config/spotless/copyright.java')
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
groovyGradle {
target '**/*.gradle'
trimTrailingWhitespace()
endWithNewline()
}
}
afterEvaluate {
boolean isAndroidApp = project.plugins.hasPlugin("com.android.application")
boolean isAndroidLibrary = project.plugins.hasPlugin("com.android.library")
boolean usesErrorProne = project.name in useErrorProneProjects
boolean isKotlinLibrary = project.plugins.hasPlugin("org.jetbrains.kotlin.jvm") || project.plugins.hasPlugin("org.jetbrains.kotlin.android")
if ((isAndroidLibrary || isAndroidApp) && usesErrorProne) {
def configurer = { variant ->
variant.getJavaCompileProvider().configure {
options.errorprone.nullaway {
severity = CheckSeverity.ERROR
annotatedPackages.add("com.uber")
}
options.errorprone.excludedPaths = ".*/build/generated/.*"
}
}
if (isAndroidLibrary) {
project.android.libraryVariants.configureEach(configurer)
}
if (isAndroidApp) {
project.android.applicationVariants.configureEach(configurer)
}
project.android.testVariants.configureEach(configurer)
project.android.unitTestVariants.configureEach(configurer)
}
if (isAndroidLibrary || isAndroidApp) {
// TODO replace with https://issuetracker.google.com/issues/72050365 once released.
project.android {
if (isAndroidLibrary) {
libraryVariants.all {
it.generateBuildConfigProvider.configure {
it.enabled = false
}
}
variantFilter { variant ->
if (variant.buildType.name == 'debug') {
variant.setIgnore(true)
}
}
}
if (isAndroidApp) {
buildTypes {
debug {
matchingFallbacks = ['release']
}
}
variantFilter { variant ->
if (variant.buildType.name == "release") {
variant.setIgnore(true)
}
}
}
}
}
if (isKotlinLibrary) {
def extraCompilerArgs = [
// See https://github.com/bazelbuild/bazel/issues/15144
"-Xjvm-default=enable",
"-Xopt-in=kotlin.RequiresOptIn"
]
if (project.name in moduleFriends.keySet()) {
def friendName = moduleFriends[project.name]
def friendProject = rootProject.subprojects.stream().filter { it.name == friendName }.findFirst().get()
def outputJarPath = friendProject.plugins.hasPlugin("com.android.library")
? "build/intermediates/compile_library_classes_jar/release/classes.jar"
: "build/libs/$friendName-${project.property('VERSION_NAME')}.jar"
def friendPath="${project.rootDir}/libraries/${moduleFriends[project.name]}/$outputJarPath"
extraCompilerArgs.add("-Xfriend-paths=$friendPath")
}
if (isAndroidLibrary || isAndroidApp) {
project.android.sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
freeCompilerArgs = extraCompilerArgs
jvmTarget = "1.8"
}
}
} else {
project.compileKotlin {
kotlinOptions {
freeCompilerArgs = extraCompilerArgs
jvmTarget = "1.8"
}
}
project.compileTestKotlin {
kotlinOptions {
freeCompilerArgs = extraCompilerArgs
jvmTarget = "1.8"
}
}
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply from: rootProject.file('gradle/japicmp.gradle')