-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
build.gradle.kts
204 lines (177 loc) · 5.84 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import com.vanniktech.maven.publish.MavenPublishPluginExtension
import io.sentry.android.gradle.internal.ASMifyTask
import io.sentry.android.gradle.internal.BootstrapAndroidSdk
import org.gradle.api.internal.classpath.ModuleRegistry
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.configurationcache.extensions.serviceOf
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version BuildPluginsVersion.KOTLIN
id("distribution")
id("groovy")
id("org.jetbrains.dokka") version BuildPluginsVersion.DOKKA
id("java-gradle-plugin")
id("com.vanniktech.maven.publish") version BuildPluginsVersion.MAVEN_PUBLISH apply false
id("org.jlleitschuh.gradle.ktlint") version BuildPluginsVersion.KTLINT
// we need this plugin in order to include .aar dependencies into a pure java project, which the gradle plugin is
id("com.stepango.aar2jar") version BuildPluginsVersion.AAR_2_JAR
}
repositories {
mavenLocal()
mavenCentral()
google()
}
BootstrapAndroidSdk.locateAndroidSdk(project, extra)
val androidSdkPath: String? by extra
val testImplementationAar by configurations.getting // this converts .aar into .jar dependencies
dependencies {
compileOnly(gradleApi())
compileOnly(Libs.AGP)
compileOnly(Libs.PROGUARD)
compileOnly(Libs.ASM)
compileOnly(Libs.ASM_COMMONS)
testImplementation(gradleTestKit())
testImplementation(kotlin("test"))
testImplementation(Libs.AGP)
testImplementation(Libs.PROGUARD)
testImplementation(Libs.JUNIT)
testImplementation(Libs.MOCKITO_KOTLIN)
testImplementation(Libs.ASM)
testImplementation(Libs.ASM_COMMONS)
// we need these dependencies for tests, because the bytecode verifier also analyzes superclasses
testImplementationAar(Libs.SQLITE)
testImplementationAar(Libs.SQLITE_FRAMEWORK)
testRuntimeOnly(files(androidSdkPath))
testRuntimeOnly(Libs.SENTRY_ANDROID)
testRuntimeOnly(
files(
serviceOf<ModuleRegistry>().getModule("gradle-tooling-api-builders")
.classpath.asFiles.first()
)
)
}
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
// We need to compile Groovy first and let Kotlin depend on it.
// See https://docs.gradle.org/6.1-rc-1/release-notes.html#compilation-order
tasks.withType<GroovyCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = JavaVersion.VERSION_11.toString()
classpath = sourceSets["main"].compileClasspath
}
tasks.withType<KotlinCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = JavaVersion.VERSION_11.toString()
classpath += files(sourceSets["main"].groovy.classesDirectory)
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
freeCompilerArgs = listOf("-Xopt-in=kotlin.RequiresOptIn", "-Xjvm-default=enable")
languageVersion = "1.4"
}
}
tasks.withType<Test>().configureEach {
maxParallelForks = Runtime.getRuntime().availableProcessors() / 2
}
gradlePlugin {
plugins {
register("sentryPlugin") {
id = "io.sentry.android.gradle"
implementationClass = "io.sentry.android.gradle.SentryPlugin"
}
}
}
ktlint {
debug.set(false)
verbose.set(true)
android.set(true)
outputToConsole.set(true)
ignoreFailures.set(false)
enableExperimentalRules.set(true)
filter {
exclude("**/generated/**")
include("**/kotlin/**")
}
}
val sep = File.separator
distributions {
main {
contents {
from("build${sep}libs")
from("build${sep}publications${sep}maven")
}
}
create("sentryPluginMarker") {
contents {
from("build${sep}publications${sep}sentryPluginPluginMarkerMaven")
}
}
}
apply {
plugin("com.vanniktech.maven.publish")
}
val publish = extensions.getByType(MavenPublishPluginExtension::class.java)
// signing is done when uploading files to MC
// via gpg:sign-and-deploy-file (release.kts)
publish.releaseSigningEnabled = false
tasks.named("distZip") {
dependsOn("publishToMavenLocal")
onlyIf {
inputs.sourceFiles.isEmpty.not().also {
require(it) { "No distribution to zip." }
}
}
}
tasks.withType<Test> {
testLogging {
events = setOf(
TestLogEvent.SKIPPED,
TestLogEvent.PASSED,
TestLogEvent.FAILED
)
showStandardStreams = true
}
}
val downloadSentryCLI = tasks.register<Exec>("downloadSentryCLI") {
onlyIf {
shouldDownloadSentryCli()
}
doFirst {
logger.lifecycle("Downloading Sentry CLI...")
}
executable("sh")
workingDir("../plugin-build")
args("-c", "./download-sentry-cli.sh")
}
tasks.named("processResources").configure {
dependsOn(downloadSentryCLI)
}
/**
* Checks whether the sentry-cli.properties matches the copy in `./src/main/resources/bin/`.
* If it doesn't, the CLI should be re-downloaded.
*/
fun shouldDownloadSentryCli(): Boolean {
val cliDir: Array<File> = File(
"$projectDir/src/main/resources/bin/"
).listFiles() ?: emptyArray()
val expectedSpec = File("$projectDir/sentry-cli.properties")
val actualSpec = File("$projectDir/src/main/resources/bin/sentry-cli.properties")
return when {
cliDir.size <= 2 -> {
logger.lifecycle("Sentry CLI is missing")
true
}
!actualSpec.exists() -> {
logger.lifecycle("Sentry CLI version specification is missing")
true
}
expectedSpec.readText() != actualSpec.readText() -> {
logger.lifecycle("Downloaded Sentry CLI version specification doesn't match")
true
}
else -> false
}
}
tasks.register<ASMifyTask>("asmify")