-
Notifications
You must be signed in to change notification settings - Fork 123
/
build.gradle
205 lines (179 loc) · 6.73 KB
/
build.gradle
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
205
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Top-level build file where you can add configuration options common to all sub-projects/modules.
// This is based off:
// https://github.com/mozilla/application-services/blob/84e077d1534dc287bbd472da658ce22eea5af032/build.gradle
buildscript {
ext.build = [
ndkVersion: "26.2.11394342", // Keep it in sync in TC Dockerfile.
compileSdkVersion: 34,
targetSdkVersion: 34,
minSdkVersion: 21,
jvmTargetCompatibility: 17,
]
repositories {
google()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath libs.kotlin.gradle.plugin
classpath libs.mozilla.rust.android.gradle
classpath libs.tools.android.plugin
classpath libs.tools.serialization
// Yes, this is unusual. We want to access some host-specific
// computation at build time.
classpath libs.jna
}
}
plugins {
alias libs.plugins.detekt
}
allprojects {
repositories {
google()
mavenCentral()
maven {
url "https://maven.mozilla.org/maven2"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// Avoid Gradle namespace collision. This is here, rather than in `buildscript
// { ... }`, to avoid issues with importing.
import com.sun.jna.Platform as DefaultPlatform
// application-services has hooks to download external dependencies here. This
// has been removed since `glean-core` doesn't have any external dependencies for now.
Properties localProperties = null
if (file('local.properties').canRead()) {
localProperties = new Properties()
localProperties.load(file('local.properties').newDataInputStream())
logger.lifecycle('Local configuration: loaded local.properties')
}
// Default to debug builds, but force release builds on CI
ext.cargoProfile = "debug"
// Additionally, we require `--locked` in CI, but not for local builds.
// Unlike the above, this can't be overridden by `local.properties` (mainly
// because doing so seems pointless, not for any security reason)
// For debug builds we also enable the `env_logger`,
// so that local testing can get some output
ext.extraCargoBuildArguments = ["--features=enable_env_logger"]
if (System.getenv("CI")) {
// Note: CI can still override this (and does for PRs), this
// is just the default
ext.cargoProfile = "release"
ext.extraCargoBuildArguments = ["--locked"]
}
// The Cargo targets to invoke. The mapping from short name to target
// triple is defined by the `rust-android-gradle` plugin.
// They can be overwritten in `local.properties` by the `rust.targets`
// attribute.
ext.rustTargets = [
'arm',
'arm64',
'x86_64',
'x86',
]
// Generate libs for our current platform so we can run unit tests.
switch (DefaultPlatform.RESOURCE_PREFIX) {
case 'darwin':
case 'darwin-x86-64':
ext.nativeRustTarget = 'darwin-x86-64'
break
case 'darwin-aarch64':
ext.nativeRustTarget = 'darwin-aarch64'
break
case 'linux-x86-64':
ext.nativeRustTarget = 'linux-x86-64'
break
case 'win32-x86-64':
ext.nativeRustTarget = 'win32-x86-64-gnu'
break
}
ext.rustTargets += ext.nativeRustTarget
subprojects {
apply plugin: 'maven-publish'
// Kotlin settings applicable to all modules.
afterEvaluate {
if (it.hasProperty('android')) {
android {
// This shouldn't be needed anymore with AGP 8.1.0+
// https://kotlinlang.org/docs/gradle-configure-project.html#gradle-java-toolchains-support
compileOptions {
sourceCompatibility rootProject.ext.build.jvmTargetCompatibility
targetCompatibility rootProject.ext.build.jvmTargetCompatibility
}
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions.allWarningsAsErrors = true
kotlin.jvmToolchain(rootProject.ext.build.jvmTargetCompatibility)
}
}
// This allows to invoke Gradle like `./gradlew publishToRootProjectBuildDir` (equivalent to
// `./gradlew publish`) and also `./gradlew publishToProjectBuildDir`.
publishing {
repositories {
maven {
name = "rootProjectBuildDir"
url = "file://${project.rootProject.buildDir}/maven"
}
maven {
name = "projectBuildDir"
url = "file://${project.buildDir}/maven"
}
}
}
}
detekt {
input = files("${projectDir}/glean-core", "${projectDir}/samples/android", "buildSrc")
config = files("${projectDir}/.detekt.yml")
buildUponDefaultConfig = true
reports {
xml.enabled = false
}
}
tasks.withType(io.gitlab.arturbosch.detekt.Detekt).configureEach {
exclude("**/test/**")
exclude("**/resources/**")
exclude("**/tmp/**")
exclude("**/build/**")
}
configurations {
ktlint
}
dependencies {
ktlint(libs.ktlint) {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
}
}
}
task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
mainClass.set("com.pinterest.ktlint.Main")
args "${projectDir}/glean-core/**/*.kt", "${projectDir}/samples/android/**/*.kt", "buildSrc/**/*.kt", "!**/build/**"
}
task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
mainClass.set("com.pinterest.ktlint.Main")
args "-F", "${projectDir}/glean-core/**/*.kt", "${projectDir}/samples/android/**/*.kt", "buildSrc/**/*.kt", "!**/build/**"
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") // workaround for java.lang.ExceptionInInitializerError
}
// Extremely unsophisticated way to publish a local development version while hiding implementation details.
//
// This shells out to a python script that tries to detect whether the working directory has changed since the last
// time it was run, and it so then it shells out to `./gradlew publishToMavenLocal -Plocal=<timestamp>` to publish
// a new version of of the code with an auto-incrementing version number.
task autoPublishForLocalDevelopment(type: Exec) {
commandLine "./build-scripts/publish_to_maven_local_if_modified.py"
}