Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 1) Change agpVersion
* 2) Run './gradlew dumpSources'
* 3) Check changeset into source control
*/
def agpVersion = 'UPDATE_THIS'
repositories {
google()
jcenter()
}
configurations {
agp
}
dependencies {
agp "com.android.tools.build:gradle:${agpVersion}"
}
task dumpSources {
inputs.files configurations.agp
outputs.dir "com.android.tools.build/$agpVersion/"
doLast {
def componentIds = configurations.agp.incoming.resolutionResult.allDependencies
.findAll { it.selected.id.group.startsWith('com.android.tools') }
.collect { it.selected.id }
.toSet()
ArtifactResolutionResult result = dependencies.createArtifactResolutionQuery()
.forComponents(componentIds)
.withArtifacts(JvmLibrary, SourcesArtifact)
.execute()
result.resolvedComponents.each { ComponentArtifactsResult component ->
Set<ArtifactResult> sources = component.getArtifacts(SourcesArtifact)
sources.each { ArtifactResult ar ->
println "Found ${ar.file}."
if (ar instanceof ResolvedArtifactResult) {
def group = ar.id.componentIdentifier.group
def module = ar.id.componentIdentifier.module
def version = ar.id.componentIdentifier.version
println "Extracting to com.android.tools.build/$agpVersion/$group/$module/$version."
copy {
from zipTree(ar.file)
into file("com.android.tools.build/$agpVersion/$group/$module/$version")
}
println "Done extracting $module."
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.