Skip to content

Commit

Permalink
Merge pull request #2697 from square/jwilson.0806.kts
Browse files Browse the repository at this point in the history
Convert builds to KTS
  • Loading branch information
pyricau committed Aug 28, 2024
2 parents 315b335 + ffdf55c commit 02d0d8b
Show file tree
Hide file tree
Showing 69 changed files with 1,154 additions and 1,101 deletions.
112 changes: 58 additions & 54 deletions build.gradle → build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import org.jetbrains.dokka.gradle.DokkaTask
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import java.net.URL
import kotlinx.validation.ApiValidationExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
ext.versions = [
'minSdk' : 14,
'compileSdk': 34,
]
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath libs.gradlePlugin.android
classpath libs.gradlePlugin.kotlin
classpath libs.gradlePlugin.dokka
classpath libs.gradlePlugin.mavenPublish
classpath libs.gradlePlugin.detekt
classpath libs.gradlePlugin.binaryCompatibility
classpath libs.gradlePlugin.keeper
classpath libs.gradlePlugin.sqldelight
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.43.2'
classpath(libs.gradlePlugin.android)
classpath(libs.gradlePlugin.kotlin)
classpath(libs.gradlePlugin.dokka)
classpath(libs.gradlePlugin.mavenPublish)
classpath(libs.gradlePlugin.detekt)
classpath(libs.gradlePlugin.binaryCompatibility)
classpath(libs.gradlePlugin.keeper)
classpath(libs.gradlePlugin.sqldelight)
classpath("com.google.dagger:hilt-android-gradle-plugin:2.43.2")
}
}

Expand All @@ -29,16 +31,16 @@ buildscript {
// When making a change that results in a public ABI change, the apiCheck task will fail. When this
// happens, run ./gradlew apiDump to generate updated *.api files, and add those to your commit.
// See https://github.com/Kotlin/binary-compatibility-validator
apply plugin: 'binary-compatibility-validator'
apply(plugin = "binary-compatibility-validator")

apiValidation {
extensions.configure<ApiValidationExtension> {
// Ignore projects that are not uploaded to Maven Central
ignoredProjects += ["leakcanary-app", "leakcanary-android-sample", "shark-test", "shark-hprof-test", "shark-cli"]
ignoredProjects += listOf("leakcanary-app", "leakcanary-android-sample", "shark-test", "shark-hprof-test", "shark-cli")
}

// This plugin needs to be applied to the root projects for the dokkaGfmCollector task we use to
// generate the documentation site.
apply plugin: 'org.jetbrains.dokka'
apply(plugin = "org.jetbrains.dokka")

repositories {
// Needed for the Dokka plugin.
Expand All @@ -58,30 +60,32 @@ subprojects {
jcenter()
}

apply plugin: 'io.gitlab.arturbosch.detekt'
apply(plugin = "io.gitlab.arturbosch.detekt")

tasks.withType(JavaCompile).configureEach {
options.compilerArgs += [
'-Xlint:all',
'-Xlint:-serial',
'-Xlint:-deprecation',
tasks.withType<JavaCompile> {
options.compilerArgs.addAll(
listOf(
"-Xlint:all",
"-Xlint:-serial",
"-Xlint:-deprecation",
// espresso-core classes say they're compiled with 51.0 but contain 52.0 attributes.
// warning: [classfile] MethodParameters attribute introduced in version 52.0 class files is ignored in version 51.0 class files
// '-Werror'
]
// "-Werror"
)
)
}

tasks.withType(Test).configureEach {
tasks.withType<Test> {
testLogging {
exceptionFormat 'FULL'
showCauses true
showExceptions true
showStackTraces true
exceptionFormat = TestExceptionFormat.FULL
showCauses = true
showExceptions = true
showStackTraces = true
}
}

detekt {
config = rootProject.files('config/detekt-config.yml')
extensions.configure<DetektExtension> {
config = rootProject.files("config/detekt-config.yml")
parallel = true
reports {
xml.enabled = false
Expand All @@ -96,30 +100,30 @@ subprojects {
}

// Config shared for subprojects except leakcanary-deobfuscation-gradle-plugin
configure(subprojects.findAll {
!(["leakcanary-deobfuscation-gradle-plugin"].contains(it.name))
configure(subprojects.filter {
it.name !in listOf("leakcanary-deobfuscation-gradle-plugin")
}) {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = "1.8"
}
}
}

// Config shared for subprojects except apps
configure(subprojects.findAll {
!(["leakcanary-app", "leakcanary-android-sample"].contains(it.name))
configure(subprojects.filter {
it.name !in listOf("leakcanary-app", "leakcanary-android-sample")
}) {
// Note: to skip Dokka on some projects we could add it individually to projects we actually
// want.
apply plugin: 'org.jetbrains.dokka'
group = GROUP
version = VERSION_NAME
apply(plugin = "org.jetbrains.dokka")
group = property("GROUP").toString()
version = property("VERSION_NAME").toString()

tasks.withType(DokkaTask.class).configureEach {
tasks.withType<DokkaTask> {
dokkaSourceSets.configureEach {
reportUndocumented.set(false)
displayName.set(null)
displayName.set(null as String?)
platform.set(org.jetbrains.dokka.Platform.jvm)

perPackageOption {
Expand All @@ -134,16 +138,16 @@ configure(subprojects.findAll {
}
skipDeprecated.set(true)
externalDocumentationLink {
url.set(new URL("https://square.github.io/okio/2.x/okio/"))
url.set(URL("https://square.github.io/okio/2.x/okio/"))
}
externalDocumentationLink {
url.set(new URL("https://square.github.io/moshi/1.x/moshi/"))
url.set(URL("https://square.github.io/moshi/1.x/moshi/"))
}
}
}

pluginManager.withPlugin("com.vanniktech.maven.publish") {
mavenPublishing {
extensions.configure<MavenPublishBaseExtension> {
publishToMavenCentral(SonatypeHost.S01)
signAllPublications()
}
Expand All @@ -152,13 +156,13 @@ configure(subprojects.findAll {

//Copies git hooks from /hooks folder into .git; currently used to run Detekt during push
//Git hook installation
tasks.register("installGitHooks", Copy) {
from new File(rootProject.rootDir, 'config/hooks')
into { new File(rootProject.rootDir, '.git/hooks') }
fileMode 0777 //Make files executable
tasks.register<Copy>("installGitHooks") {
from(File(rootProject.rootDir, "config/hooks"))
into({ File(rootProject.rootDir, ".git/hooks") })
fileMode = "0777".toInt(8) // Make files executable
}

tasks.register("siteDokka", Copy) {
tasks.register<Copy>("siteDokka") {
description = "Generate dokka Github-flavored Markdown for the documentation site."
group = "documentation"
dependsOn(":dokkaGfmCollector")
Expand All @@ -169,11 +173,11 @@ tasks.register("siteDokka", Copy) {
from(layout.buildDirectory.dir("dokka/gfmCollector/leakcanary-repo"))
// For whatever reason Dokka doesn't want to ignore the packages we told it to ignore.
// Fine, we'll just ignore it here.
exclude '**/com.example.leakcanary/**'
exclude("**/com.example.leakcanary/**")
into(rootProject.file("docs/api"))

filter { line ->
// Dokka adds [main]\ and [main]<br> everywhere, this just removes it.
line.replaceAll("\\[main\\]\\\\", "").replaceAll("\\[main\\]<br>", "")
line.replace("\\[main\\]\\\\", "").replace("\\[main\\]<br>", "")
}
}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
[versions]
# We would like to use Kotlin recent language features but keep Kotlin 1.3 library APIs
# The benefit is that depending clients do not have to upgrade to Kotlin 1.4
compose = "1.4.3"
kotlin = "1.8.21"
coroutines = "1.7.3"
androidXTest = "1.1.0"
androidXJunit = "1.1.3"
workManager = "2.7.0"
androidMinSdk = "14"
androidCompileSdk = "34"

[libraries]
gradlePlugin-android = { module = "com.android.tools.build:gradle", version = "8.0.0" }
Expand Down
59 changes: 0 additions & 59 deletions leakcanary/leakcanary-android-core/build.gradle

This file was deleted.

66 changes: 66 additions & 0 deletions leakcanary/leakcanary-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import java.io.InputStreamReader

plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("com.vanniktech.maven.publish")
}

dependencies {
api(projects.shark.sharkAndroid)
api(projects.objectWatcher.objectWatcherAndroidCore)
api(projects.objectWatcher.objectWatcherAndroidAndroidx)
api(projects.leakcanary.leakcanaryAndroidUtils)
implementation(libs.kotlin.stdlib)

// Optional dependency
compileOnly(libs.androidX.work.runtime)
compileOnly(libs.androidX.work.multiprocess)

testImplementation(libs.assertjCore)
testImplementation(libs.junit)
testImplementation(libs.kotlin.reflect)
testImplementation(libs.mockito)
testImplementation(libs.mockitoKotlin)
androidTestImplementation(libs.androidX.test.espresso)
androidTestImplementation(libs.androidX.test.rules)
androidTestImplementation(libs.androidX.test.runner)
androidTestImplementation(libs.assertjCore)
androidTestImplementation(projects.shark.sharkHprofTest)
androidTestUtil(libs.androidX.test.orchestrator)
}

fun gitSha(): String {
val process = ProcessBuilder("git", "rev-parse", "--short", "HEAD").start()
return InputStreamReader(process.inputStream).readText().trim()
}

android {
resourcePrefix = "leak_canary_"
compileSdk = libs.versions.androidCompileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.androidMinSdk.get().toInt()
// Avoid DeprecatedTargetSdkVersionDialog during UI tests
targetSdk = libs.versions.androidCompileSdk.get().toInt()
buildConfigField("String", "LIBRARY_VERSION", "\"${rootProject.property("VERSION_NAME")}\"")
buildConfigField("String", "GIT_SHA", "\"${gitSha()}\"")
consumerProguardFiles("consumer-proguard-rules.pro")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

testInstrumentationRunnerArguments(
mapOf(
"clearPackageData" to "true",
)
)
testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}
namespace = "com.squareup.leakcanary.core"
testNamespace = "com.squareup.leakcanary.core.test"
lint {
checkOnly += "Interoperability"
disable += "GoogleAppIndexingWarning"
error += "ObsoleteSdkInt"
}
}
44 changes: 0 additions & 44 deletions leakcanary/leakcanary-android-instrumentation/build.gradle

This file was deleted.

Loading

0 comments on commit 02d0d8b

Please sign in to comment.