Add full offline Android Gradle Plugin dependency cache

This commit is contained in:
lendry
2026-06-26 23:05:44 +03:00
parent 0a020d6857
commit 73c292b3a5
138 changed files with 5270 additions and 47 deletions

View File

@@ -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}")
}
}

View File

@@ -650,7 +650,7 @@ code + .copy-button {
<script type="text/javascript">
function configurationCacheProblems() { return (
// begin-report-data
{"diagnostics":[{"locations":[{},{"taskPath":":exportOfflineMaven"}],"problem":[{"text":"Using method exec(Action) has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 9.0."}],"contextualLabel":"Using method exec(Action) has been deprecated.","documentationLink":"https://docs.gradle.org/8.14.3/userguide/upgrading_version_8.html#deprecated_project_exec","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"using-method-exec-action-has-been-deprecated","displayName":"Using method exec(Action) has been deprecated."}],"solutions":[[{"text":"Use ExecOperations.exec(Action) or ProviderFactory.exec(Action) instead."}]]},{"locations":[{},{"taskPath":":exportOfflineMaven"}],"problem":[{"text":"Using method exec(Action) has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 9.0."}],"contextualLabel":"Using method exec(Action) has been deprecated.","documentationLink":"https://docs.gradle.org/8.14.3/userguide/upgrading_version_8.html#deprecated_project_exec","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"using-method-exec-action-has-been-deprecated","displayName":"Using method exec(Action) has been deprecated."}],"solutions":[[{"text":"Use ExecOperations.exec(Action) or ProviderFactory.exec(Action) instead."}]]}],"problemsReport":{"totalProblemCount":2,"buildName":"agp-resolver","requestedTasks":"exportOfflineMaven","documentationLink":"https://docs.gradle.org/8.14.3/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
{"diagnostics":[{"locations":[{},{"taskPath":":exportAllOfflineMaven"}],"problem":[{"text":"Using method exec(Action) has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 9.0."}],"contextualLabel":"Using method exec(Action) has been deprecated.","documentationLink":"https://docs.gradle.org/8.14.3/userguide/upgrading_version_8.html#deprecated_project_exec","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"using-method-exec-action-has-been-deprecated","displayName":"Using method exec(Action) has been deprecated."}],"solutions":[[{"text":"Use ExecOperations.exec(Action) or ProviderFactory.exec(Action) instead."}]]},{"locations":[{},{"taskPath":":exportAllOfflineMaven"}],"problem":[{"text":"Using method exec(Action) has been deprecated."}],"severity":"WARNING","problemDetails":[{"text":"This is scheduled to be removed in Gradle 9.0."}],"contextualLabel":"Using method exec(Action) has been deprecated.","documentationLink":"https://docs.gradle.org/8.14.3/userguide/upgrading_version_8.html#deprecated_project_exec","problemId":[{"name":"deprecation","displayName":"Deprecation"},{"name":"using-method-exec-action-has-been-deprecated","displayName":"Using method exec(Action) has been deprecated."}],"solutions":[[{"text":"Use ExecOperations.exec(Action) or ProviderFactory.exec(Action) instead."}]]}],"problemsReport":{"totalProblemCount":2,"buildName":"agp-resolver","requestedTasks":"exportAllOfflineMaven","documentationLink":"https://docs.gradle.org/8.14.3/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
// end-report-data
);}
</script>