1import org.jetbrains.dokka.gradle.DokkaTask 2 3buildscript { 4 ext.versions = [ 5 'minSdk' : 14, 6 'compileSdk': 34, 7 ] 8 repositories { 9 google() 10 gradlePluginPortal() 11 mavenCentral() 12 } 13 dependencies { 14 classpath libs.gradlePlugin.android 15 classpath libs.gradlePlugin.kotlin 16 classpath libs.gradlePlugin.dokka 17 classpath libs.gradlePlugin.mavenPublish 18 classpath libs.gradlePlugin.detekt 19 classpath libs.gradlePlugin.binaryCompatibility 20 classpath libs.gradlePlugin.keeper 21 } 22} 23 24// We use JetBrain's Kotlin Binary Compatibility Validator to track changes to our public binary 25// APIs. 26// When making a change that results in a public ABI change, the apiCheck task will fail. When this 27// happens, run ./gradlew apiDump to generate updated *.api files, and add those to your commit. 28// See https://github.com/Kotlin/binary-compatibility-validator 29apply plugin: 'binary-compatibility-validator' 30 31apiValidation { 32 // Ignore projects that are not uploaded to Maven Central 33 ignoredProjects += ["leakcanary-android-sample", "shark-test", "shark-hprof-test", "shark-cli"] 34} 35 36// This plugin needs to be applied to the root projects for the dokkaGfmCollector task we use to 37// generate the documentation site. 38apply plugin: 'org.jetbrains.dokka' 39 40repositories { 41 // Needed for the Dokka plugin. 42 gradlePluginPortal() 43} 44 45subprojects { 46 // Note: to skip Dokka on some projects we could add it individually to projects we actually 47 // want. 48 apply plugin: 'org.jetbrains.dokka' 49 group = GROUP 50 version = VERSION_NAME 51 52 repositories { 53 google() 54 mavenCentral() 55 // maven { 56 // url 'https://oss.sonatype.org/content/repositories/snapshots/' 57 // } 58 // mavenLocal() 59 jcenter() 60 } 61 62 apply plugin: 'io.gitlab.arturbosch.detekt' 63 64 tasks.withType(DokkaTask.class).configureEach { 65 dokkaSourceSets.configureEach { 66 reportUndocumented.set(false) 67 displayName.set(null) 68 platform.set(org.jetbrains.dokka.Platform.jvm) 69 70 perPackageOption { 71 // will match all .internal packages and sub-packages 72 matchingRegex.set("(.*\\.internal.*)") 73 suppress.set(true) 74 } 75 perPackageOption { 76 // BuildConfig files 77 matchingRegex.set("com.squareup.leakcanary\\..*") 78 suppress.set(true) 79 } 80 perPackageOption { 81 // Example app 82 matchingRegex.set("com.example.leakcanary\\..*") 83 suppress.set(true) 84 } 85 skipDeprecated.set(true) 86 externalDocumentationLink { 87 url.set(new URL("https://square.github.io/okio/2.x/okio/")) 88 } 89 externalDocumentationLink { 90 url.set(new URL("https://square.github.io/moshi/1.x/moshi/")) 91 } 92 } 93 } 94 95 pluginManager.withPlugin("com.vanniktech.maven.publish") { 96 mavenPublish { 97 sonatypeHost = "S01" 98 } 99 } 100 101 tasks.withType(JavaCompile).configureEach { 102 options.compilerArgs += [ 103 '-Xlint:all', 104 '-Xlint:-serial', 105 '-Xlint:-deprecation', 106 // espresso-core classes say they're compiled with 51.0 but contain 52.0 attributes. 107 // warning: [classfile] MethodParameters attribute introduced in version 52.0 class files is ignored in version 51.0 class files 108 // '-Werror' 109 ] 110 } 111 112 tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { 113 kotlinOptions { 114 // Avoid warnings of using older stdlib version 1.3 than compiler version 1.4 115 apiVersion = "1.3" 116 } 117 } 118 119 tasks.withType(Test).configureEach { 120 testLogging { 121 exceptionFormat 'FULL' 122 showCauses true 123 showExceptions true 124 showStackTraces true 125 } 126 } 127 128 detekt { 129 config = rootProject.files('detekt-config.yml') 130 parallel = true 131 reports { 132 xml.enabled = false 133 } 134 } 135 136 pluginManager.withPlugin("java") { 137 tasks.named("check") { dependsOn("detekt") } 138 tasks.named("assemble") { dependsOn(rootProject.tasks.named("installGitHooks")) } 139 tasks.named("clean") { dependsOn(rootProject.tasks.named("installGitHooks")) } 140 } 141} 142 143//Copies git hooks from /hooks folder into .git; currently used to run Detekt during push 144//Git hook installation 145tasks.register("installGitHooks", Copy) { 146 from new File(rootProject.rootDir, 'hooks') 147 into { new File(rootProject.rootDir, '.git/hooks') } 148 fileMode 0777 //Make files executable 149} 150 151tasks.register("siteDokka", Copy) { 152 description = "Generate dokka Github-flavored Markdown for the documentation site." 153 group = "documentation" 154 dependsOn(":dokkaGfmCollector") 155 156 // Copy the files instead of configuring a different output directory on the dokka task itself 157 // since the default output directories disambiguate between different types of outputs, and our 158 // custom directory doesn't. 159 from(layout.buildDirectory.dir("dokka/gfmCollector/leakcanary")) 160 // For whatever reason Dokka doesn't want to ignore the packages we told it to ignore. 161 // Fine, we'll just ignore it here. 162 exclude '**/com.example.leakcanary/**' 163 into(rootProject.file("docs/api")) 164 165 filter { line -> 166 // Dokka adds [main]\ and [main]<br> everywhere, this just removes it. 167 line.replaceAll("\\[main\\]\\\\", "").replaceAll("\\[main\\]<br>", "") 168 } 169} 170