Add full offline Android Gradle Plugin dependency cache
This commit is contained in:
@@ -13,42 +13,19 @@ val agpVersion: String = providers.gradleProperty("agpVersion").orElse("8.11.0")
|
||||
|
||||
configurations {
|
||||
create("agp")
|
||||
create("androidDeps")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
add("agp", "com.android.tools.build:gradle:$agpVersion")
|
||||
}
|
||||
|
||||
tasks.register("exportOfflineMaven") {
|
||||
dependsOn(configurations.named("agp"))
|
||||
doLast {
|
||||
val offlineRoot = file("${rootProject.projectDir}/../offline-maven").apply { mkdirs() }
|
||||
val configuration = configurations.getByName("agp")
|
||||
val resolved = configuration.resolvedConfiguration
|
||||
val modules = linkedSetOf<Triple<String, String, String>>()
|
||||
|
||||
resolved.resolvedArtifacts.forEach { artifact ->
|
||||
val id = artifact.moduleVersion.id
|
||||
modules.add(Triple(id.group, id.name, id.version))
|
||||
installArtifact(
|
||||
offlineRoot,
|
||||
id.group,
|
||||
id.name,
|
||||
id.version,
|
||||
artifact.extension ?: "jar",
|
||||
artifact.file,
|
||||
)
|
||||
}
|
||||
|
||||
modules.forEach { (group, name, version) ->
|
||||
ensurePom(offlineRoot, group, name, version)
|
||||
}
|
||||
|
||||
file("${offlineRoot.absolutePath}/.agp-offline-complete").writeText(
|
||||
"agpVersion=$agpVersion\nmodules=${modules.size}\n",
|
||||
)
|
||||
println("Exported ${modules.size} modules to ${offlineRoot.absolutePath}")
|
||||
}
|
||||
add("androidDeps", "androidx.webkit:webkit:1.14.0")
|
||||
add("androidDeps", "androidx.appcompat:appcompat:1.7.1")
|
||||
add("androidDeps", "androidx.activity:activity-ktx:1.10.1")
|
||||
add("androidDeps", "com.google.android.material:material:1.12.0")
|
||||
add("androidDeps", "androidx.lifecycle:lifecycle-process:2.10.0")
|
||||
add("androidDeps", "androidx.core:core-ktx:1.9.0")
|
||||
add("androidDeps", "androidx.browser:browser:1.8.0")
|
||||
}
|
||||
|
||||
fun installArtifact(
|
||||
@@ -104,3 +81,54 @@ fun ensurePom(root: File, group: String, name: String, version: String) {
|
||||
|
||||
throw GradleException("POM not found: $group:$name:$version")
|
||||
}
|
||||
|
||||
fun exportConfiguration(configName: String, offlineRoot: File): Int {
|
||||
val configuration = configurations.getByName(configName)
|
||||
val modules = linkedSetOf<Triple<String, String, String>>()
|
||||
|
||||
configuration.resolvedConfiguration.resolvedArtifacts.forEach { artifact ->
|
||||
val id = artifact.moduleVersion.id
|
||||
modules.add(Triple(id.group, id.name, id.version))
|
||||
installArtifact(
|
||||
offlineRoot,
|
||||
id.group,
|
||||
id.name,
|
||||
id.version,
|
||||
artifact.extension ?: "jar",
|
||||
artifact.file,
|
||||
)
|
||||
}
|
||||
|
||||
modules.forEach { (group, name, version) ->
|
||||
ensurePom(offlineRoot, group, name, version)
|
||||
}
|
||||
|
||||
println("Exported ${modules.size} modules from configuration ${configName}")
|
||||
return modules.size
|
||||
}
|
||||
|
||||
tasks.register("exportOfflineMaven") {
|
||||
dependsOn(configurations.named("agp"))
|
||||
doLast {
|
||||
val offlineRoot = file("${rootProject.projectDir}/../offline-maven").apply { mkdirs() }
|
||||
val modules = exportConfiguration("agp", offlineRoot)
|
||||
file("${offlineRoot.absolutePath}/.agp-offline-complete").writeText(
|
||||
"agpVersion=$agpVersion\nmodules=$modules\n",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("exportAllOfflineMaven") {
|
||||
dependsOn(configurations.named("agp"), configurations.named("androidDeps"))
|
||||
doLast {
|
||||
val offlineRoot = file("${rootProject.projectDir}/../offline-maven").apply { mkdirs() }
|
||||
val modules = exportConfiguration("agp", offlineRoot) + exportConfiguration("androidDeps", offlineRoot)
|
||||
file("${offlineRoot.absolutePath}/.agp-offline-complete").writeText(
|
||||
"agpVersion=$agpVersion\nmodules=$modules\n",
|
||||
)
|
||||
file("${offlineRoot.absolutePath}/.android-deps-offline-complete").writeText(
|
||||
"modules=$modules\n",
|
||||
)
|
||||
println("Exported ${modules} total modules to ${offlineRoot.absolutePath}")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user