forked from AndroidIDEOfficial/AndroidIDE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
executable file
·248 lines (209 loc) · 7.8 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
@file:Suppress("UnstableApiUsage")
import com.android.build.gradle.BaseExtension
import com.itsaky.androidide.plugins.AndroidIDEPlugin
import com.vanniktech.maven.publish.AndroidMultiVariantLibrary
import com.vanniktech.maven.publish.GradlePlugin
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost.Companion.S01
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("build-logic.root-project")
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin) apply false
alias(libs.plugins.maven.publish) apply false
alias(libs.plugins.gradle.publish) apply false
}
buildscript {
dependencies {
classpath("com.google.android.gms:oss-licenses-plugin:0.10.6")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0")
}
}
val flavorsAbis = arrayOf("arm64-v8a", "armeabi-v7a")
fun Project.configureBaseExtension() {
extensions.findByType(BaseExtension::class)?.run {
compileSdkVersion(BuildConfig.compileSdk)
defaultConfig {
minSdk = BuildConfig.minSdk
targetSdk = BuildConfig.targetSdk
versionCode = projectVersionCode
versionName = rootProject.version.toString()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = BuildConfig.javaVersion
targetCompatibility = BuildConfig.javaVersion
}
if (":app" == project.path) {
flavorDimensions("default")
productFlavors {
flavorsAbis.forEach(this::create)
forEach {
val name = it.name
defaultConfig.buildConfigField("String",
"FLAVOR_${name.replace('-', '_').uppercase()}",
"\"${name}\"")
}
}
}
// configure split APKs for ':app' module only
if (this@configureBaseExtension == rootProject.findProject(":app")) {
splits {
abi {
reset()
isEnable = true
isUniversalApk = false
// TODO: Find a way to enable split APKs in product flavors. If this is possible, we can configure
// each flavor to include only a single ABI. For example, for the 'arm64-v8a' flavor,
// we can configure it to generate APK only for 'arm64-v8a'.
//
// See the contribution guidelines for more information.
@Suppress("ChromeOsAbiSupport")
include(*flavorsAbis)
}
}
}
buildTypes.getByName("debug") { isMinifyEnabled = false }
buildTypes.getByName("release") {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
testOptions { unitTests.isIncludeAndroidResources = true }
buildFeatures.viewBinding = true
buildFeatures.buildConfig = true
}
}
subprojects {
afterEvaluate {
apply { plugin(AndroidIDEPlugin::class.java) }
}
project.group = BuildConfig.packageName
project.version = rootProject.version
plugins.withId("com.android.application") { configureBaseExtension() }
plugins.withId("com.android.library") { configureBaseExtension() }
plugins.withId("java-library") {
configure<JavaPluginExtension> {
sourceCompatibility = BuildConfig.javaVersion
targetCompatibility = BuildConfig.javaVersion
}
}
project.afterEvaluate {
if (project.plugins.hasPlugin(
"com.vanniktech.maven.publish.base") && project.description.isNullOrBlank()
) {
throw GradleException("Project ${project.path} must have a description")
}
}
plugins.withId("com.vanniktech.maven.publish.base") {
configure<MavenPublishBaseExtension> {
project.configureMavenLocal()
pom {
name.set(project.name)
description.set(project.description)
inceptionYear.set("2021")
url.set(ProjectConfig.REPO_URL)
licenses {
license {
name.set("The GNU General Public License, v3.0")
url.set("https://www.gnu.org/licenses/gpl-3.0.en.html")
distribution.set("https://www.gnu.org/licenses/gpl-3.0.en.html")
}
}
developers {
developer {
id.set("androidide")
name.set("AndroidIDE")
url.set(ProjectConfig.PROJECT_SITE)
}
}
scm {
url.set(ProjectConfig.REPO_URL)
connection.set(ProjectConfig.SCM_GIT)
developerConnection.set(ProjectConfig.SCM_SSH)
}
}
coordinates(project.group.toString(), project.name, project.publishingVersion)
publishToMavenCentral(host = S01)
signAllPublications()
if (plugins.hasPlugin("com.android.library")) {
configure(AndroidMultiVariantLibrary())
} else if (plugins.hasPlugin("java-gradle-plugin")) {
configure(GradlePlugin(javadocJar = JavadocJar.Javadoc()))
} else if (plugins.hasPlugin("java-library")) {
configure(JavaLibrary(javadocJar = JavadocJar.Javadoc()))
}
}
}
plugins.withId("com.gradle.plugin-publish") {
configure<GradlePluginDevelopmentExtension> {
version = project.publishingVersion
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = BuildConfig.javaVersion.toString()
}
gradle.projectsEvaluated {
rootProject.subprojects {
if (project.path in projectsRequiringMavenLocalForTests) {
tasks.withType<Test> {
for ((project, _) in mavenLocalRepos) {
dependsOn(project(project).tasks.getByName("publishAllPublicationsToBuildMavenLocalRepository"))
}
}
}
}
}
}
val projectsRequiringMavenLocalForTests = arrayOf(":gradle-plugin")
val mavenLocalRepos = hashMapOf<String, String>()
fun Project.configureMavenLocal() {
val mavenLocalPath = "${buildDir}/maven-local"
mavenLocalRepos[project.path] = mavenLocalPath
extensions.findByType(PublishingExtension::class.java)?.run {
repositories {
maven {
name = "buildMavenLocal"
url = uri(mavenLocalPath)
}
}
}
tasks.create<Delete>("deleteBuildMavenLocal") {
delete(mavenLocalPath)
}
if (project.path in projectsRequiringMavenLocalForTests) {
tasks.withType<Test> {
dependsOn(tasks.getByName("publishAllPublicationsToBuildMavenLocalRepository"))
doFirst {
val file = File(mavenLocalPath, "repos.txt")
file.writeText(mavenLocalRepos.values.joinToString(separator = File.pathSeparator))
}
}
}
afterEvaluate {
tasks.getByName("publishAllPublicationsToBuildMavenLocalRepository") {
dependsOn(tasks.getByName("deleteBuildMavenLocal"))
}
}
}
tasks.register<Delete>("clean") { delete(rootProject.buildDir) }