forked from SuperMonster003/AutoJs6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
177 lines (152 loc) · 6.42 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
@file:Suppress("UnnecessaryVariable")
// Top-level build file where you can add configuration options common to all sub-projects/modules.
extra.apply {
set("configurationName", "default")
}
buildscript {
/* --== variables ==-- */
// @Hint by SuperMonster003 on May 3, 2023.
// ! To download archives of Android Studio,
// ! visit https://developer.android.com/studio/archive
// ! To check the compatibility and released date of kotlin plugins,
// ! visit https://plugins.jetbrains.com/plugin/6954-kotlin/versions/eap
val gradlePluginVersionList = mapOf(
"as" to mapOf(
"abbr" to mapOf(
"Preview2023.1" to "H", /* May 13, 2023. */
"2022.3" to "G", /* Jul 3, 2023. */
"Preview2022.3" to "G", /* May 3, 2023. */
"2022.2" to "F", /* May 3, 2023. */
"Preview2022.2" to "F", /* May 3, 2023. */
"2022.1" to "E", /* May 3, 2023. */
),
"android" to mapOf(
"Preview2023.1" to "8.2.0-alpha10", /* May 26, 2023. */
"2022.3" to "8.1.0-rc01", /* Jul 3 2023. */
"Preview2022.3" to "8.1.0-beta05", /* Jun 14 2023. */
"2022.2" to "8.0.2", /* May 26, 2023. */
"Preview2022.2" to "8.0.0-beta05", /* Mar 25, 2023. */
"2022.1" to "7.4.2", /* Mar 25, 2023. */
"fallback" to "7.4.2", /* May 3, 2023. */
),
"kotlin" to mapOf(
"Preview2023.1" to "1.9.0-RC", /* Jul 3, 2023. */
"2022.3" to "1.9.0-RC", /* Jul 3, 2023. */
"Preview2022.3" to "1.8.0", /* May 13, 2023. */
"2022.2" to "1.8.20-RC2", /* Mar 23, 2023. */
"Preview2022.2" to "1.8.0", /* Mar 23, 2023. */
"2022.1" to "1.8.0-RC2", /* Dec 20, 2022. */
"fallback" to "1.8.0-RC2", /* May 3, 2023. */
)
),
"idea" to mapOf(
"android" to mapOf(
"2023.1" to "7.4.2", /* May 26, 2023. */
"2022.3" to "7.4.0-beta02", /* Mar 25, 2023. */
"fallback" to "7.4.0", /* May 3, 2023. */
),
"kotlin" to mapOf(
// CAUTION by SuperMonster003 on Jul 3, 2023.
// ! Do not set version to "1.9.0-Beta" or "1.9.0-RC".
"2023.1" to "1.8.21", /* Apr 25, 2023. */
"2022.3" to "1.8.21", /* Apr 25, 2023. */
"fallback" to "1.8.21", /* May 3, 2023. */
),
),
)
val platform =
if (System.getProperty("idea.paths.selector") != null) System.getProperty("idea.paths.selector") else "AndroidStudio" // 设置platform默认值为"AndroidStudio",避免命令行中属性值为null引发异常
val platformIdentifierForAS = "AndroidStudio"
val platformIdentifierForIdea = "IntelliJIdea"
val isPlatformAS = platform.startsWith(platformIdentifierForAS)
val isPlatformIdea = platform.startsWith(platformIdentifierForIdea)
val platformVersion = when {
isPlatformAS -> platform.substring(platformIdentifierForAS.length)
isPlatformIdea -> platform.substring(platformIdentifierForIdea.length)
else -> "Unknown"
}
val platformType = when {
isPlatformAS -> "as"
isPlatformIdea -> "idea"
else -> throw Exception("Unknown platform: $platform")
}
val platformNicknameForAS = mapOf(
"A" to "Arctic Fox",
"B" to "Bumblebee",
"C" to "Chipmunk",
"D" to "Dolphin",
"E" to "Electric Eel",
"F" to "Flamingo",
"G" to "Giraffe",
"H" to "Hedgehog",
)
/* --== functions ==-- */
fun printCurrentPlatformInfo() = when {
isPlatformAS -> {
val platformNickAbbr = gradlePluginVersionList["as"]!!["abbr"]!![platformVersion]
val platformNick =
platformNickAbbr?.let { abbr -> platformNicknameForAS[abbr]?.let { " $it" } } ?: ""
val previewIdentifier = "Preview"
val isPreview = platformVersion.contains(previewIdentifier, true)
val previewSuffix = if (isPreview) " ($previewIdentifier)" else ""
val niceVersion =
if (isPreview) platformVersion.substring(previewIdentifier.length) else platformVersion
"Android Studio$platformNick$previewSuffix | $niceVersion"
}
isPlatformIdea -> "IntelliJ IDEA $platformVersion"
else -> "Unknown"
}.let { println("Platform: $it") }
/* --== repositories ==-- */
repositories {
mavenCentral()
google()
maven("https://maven.aliyun.com/repository/central")
maven("https://maven.aliyun.com/repository/google")
maven("https://maven.aliyun.com/repository/gradle-plugin")
maven("https://maven.aliyun.com/repository/jcenter")
maven("https://maven.aliyun.com/repository/public")
}
/* --== dependencies ==-- */
dependencies /* Print Information. */ {
printCurrentPlatformInfo()
}
dependencies /* Android/Kotlin Gradle Plugin. */ {
val android = gradlePluginVersionList[platformType]!!["android"]!!
val kotlin = gradlePluginVersionList[platformType]!!["kotlin"]!!
arrayOf(
arrayOf(
"com.android.tools.build:gradle",
android[platformVersion],
android["fallback"]
),
arrayOf(
"org.jetbrains.kotlin:kotlin-gradle-plugin",
kotlin[platformVersion],
kotlin["fallback"]
),
).forEach { data ->
val classpathNotation = "${data[0]}:${data[1] ?: data[2]}"
val suffix = data[1]?.let { "" } ?: " [fallback]"
println("Classpath: \"$classpathNotation\"$suffix")
classpath(classpathNotation)
}
}
}
allprojects {
repositories {
mavenCentral()
google()
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://maven.aliyun.com/repository/central")
maven("https://maven.aliyun.com/repository/google")
maven("https://maven.aliyun.com/repository/gradle-plugin")
maven("https://maven.aliyun.com/repository/jcenter")
maven("https://maven.aliyun.com/repository/public")
maven("https://jitpack.io")
}
}
tasks {
register<Delete>("clean").configure {
delete(rootProject.buildDir)
}
}