-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
183 lines (162 loc) · 6.95 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
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.5.2' apply false
id 'com.android.library' version '8.5.2' apply false
id 'org.jetbrains.kotlin.android' version '1.9.25' apply false
id 'com.google.dagger.hilt.android' version '2.52' apply false
id 'com.google.devtools.ksp' version '1.9.25-1.0.20' apply false
}
ext {
kotlinVer = hasProperty('kotlinVer') ? property('kotlinVer') : '1.9.25'
hiltVer = hasProperty('hiltVer') ? property('hiltVer') : '2.52'
composeBomVer = hasProperty('composeBomVer') ? property('composeBomVer') : '2024.09.01'
}
subprojects {
ext {
kotlinVer = rootProject.ext.kotlinVer
hiltVer = rootProject.ext.hiltVer
composeBomVer = rootProject.ext.composeBomVer
}
}
tasks.register("printRootVersions") {
doLast {
println "Root Project Kotlin Version: ${ext.kotlinVer}"
println "Root Project Hilt Version: ${ext.hiltVer}"
println "Root Project Compose BOM Version: ${ext.composeBomVer}"
// println "Root Project AndroidX Main Branch: ${ext.androidxMainBranch}"
}
}
tasks.register('setupDocsDirs') {
outputs.dir new File(rootDir, "docs/kotlin")
outputs.dir new File(rootDir, "docs/hilt")
outputs.dir new File(rootDir, "docs/androidx-compose")
doLast {
def docsDir = new File("${project.rootDir}/docs")
if (!docsDir.exists()) {
docsDir.mkdirs()
}
println "Created docs directory: ${docsDir.absolutePath}"
// Example subdirectories for each library or framework
['kotlin', 'hilt', 'androidx-compose'].each { sub ->
File subDir = new File(docsDir, sub)
if (!subDir.exists()) {
subDir.mkdirs()
println "Created sub-directory: ${subDir.absolutePath}"
}
}
}
}
tasks.register('downloadDocs', Exec) {
dependsOn setupDocsDirs
outputs.files(
new File(rootDir, "docs/kotlin/kotlin-compiler-${kotlinVer}.zip"),
new File(rootDir, "docs/hilt/dagger-${hiltVer}.zip"),
new File(rootDir, "docs/androidx-compose/androidx-main.tar.gz")
)
doFirst {
println "Downloading docs/source for Kotlin v${kotlinVer}, " +
"Hilt v${hiltVer}, Compose BOM v${composeBomVer}"
}
// Kotlin doc/archives -> https://kotlinlang.org/releases.html
// Hilt source code -> https://github.com/google/dagger
// Jetpack Compose code -> https://github.com/androidx/androidx
workingDir rootDir
commandLine 'sh', '-c', """
set -e
# Kotlin docs or compiler archive (example: official .zip from GitHub or kotlinlang.org)
echo ">>> Downloading Kotlin Compiler (v${kotlinVer})"
pwd
curl -fSL -o docs/kotlin/kotlin-compiler-${kotlinVer}.zip \\
https://github.com/JetBrains/kotlin/releases/download/v${kotlinVer}/kotlin-compiler-${kotlinVer}.zip
echo ">>> Downloading Hilt Source (v${hiltVer})"
curl -fSL -o docs/hilt/dagger-${hiltVer}.zip \\
https://github.com/google/dagger/archive/refs/tags/dagger-${hiltVer}.zip
echo ">>> Downloading AndroidX (Jetpack) Compose Source"
# The version-specific tags in the androidx/androidx repo can be tricky,
# so here we just clone main or use a tarball from a known commit/branch.
# For demonstration, let's do a tar of main:
curl -fSL -o docs/androidx-compose/androidx-main.tar.gz \\
https://github.com/androidx/androidx/archive/refs/heads/androidx-main.tar.gz
"""
}
// -- 4. Extract the downloaded archives --
tasks.register('extractDocs') {
dependsOn downloadDocs
outputs.dir new File(rootDir, "docs/kotlinc")
outputs.dir new File(rootDir, "docs/hilt/dagger-dagger-${hiltVer}.zip")
outputs.dir new File(rootDir, "docs/androidx-androidx-main")
doLast {
println "Extracting offline docs/source..."
def kotlinZip = new File(rootDir, "docs/kotlin/kotlin-compiler-${kotlinVer}.zip")
if (kotlinZip.exists()) {
// Optional: Verify if the ZIP is valid before extraction
// if (ant.zipValidate(src: kotlinZip)) {
ant.unzip(src: kotlinZip, dest: new File(rootDir, "docs/kotlin"))
println "Extracted Kotlin Compiler."
// kotlinZip.delete()
println "Deleted Kotlin Compiler archive."
// } else {
// throw new GradleException("Invalid ZIP archive for Kotlin Compiler: ${kotlinZip.absolutePath}")
// }
} else {
throw new GradleException("Kotlin Compiler zip not found: ${kotlinZip.absolutePath}")
}
// Extract Hilt (Dagger) zip
def hiltZip = new File(rootDir, "docs/hilt/dagger-${hiltVer}.zip")
if (hiltZip.exists()) {
// if (ant.zipValidate(src: hiltZip)) {
ant.unzip(src: hiltZip, dest: new File(rootDir, "docs/hilt"))
println "Extracted Hilt (Dagger) Source."
// hiltZip.delete()
println "Deleted Hilt Source archive."
// } else {
// throw new GradleException("Invalid ZIP archive for Hilt Source: ${hiltZip.absolutePath}")
// }
} else {
throw new GradleException("Hilt Source zip not found: ${hiltZip.absolutePath}")
}
// Extract AndroidX Compose tar.gz
def androidxTar = new File(rootDir, "docs/androidx-compose/androidx-main.tar.gz")
if (androidxTar.exists()) {
// Optionally, validate the tar.gz file here
project.exec {
commandLine 'sh', '-c', """
cd docs/androidx-compose
tar -xzf androidx-main.tar.gz
"""
}
println "Extracted AndroidX Compose Source."
// androidxTar.delete()
println "Deleted AndroidX Compose tar.gz archive."
} else {
throw new GradleException("AndroidX Compose tar.gz not found: ${androidxTar.absolutePath}")
}
println "Extraction complete!"
}
}
// -- 5. Verify and list the offline docs directories --
tasks.register('verifyDocs') {
dependsOn extractDocs
doLast {
println "Verifying offline docs presence by listing directories..."
project.exec {
commandLine 'sh', '-c', """
echo "Contents of docs/kotlin:"
tree -L 2 docs/kotlin
echo "\\nContents of docs/hilt:"
tree -L 2 docs/hilt
echo "\\nContents of docs/androidx-compose:"
tree -L 2 docs/androidx-compose
"""
}
}
}
// -- Helper Task: run everything in one go --
tasks.register('offlineDocs') {
group = "Documentation"
description = "Sets up directories, downloads, extracts, and verifies offline docs."
dependsOn verifyDocs
doLast {
println "Offline docs setup completed successfully!"
}
}