1import java.nio.file.Files 2import java.nio.file.NoSuchFileException 3import java.util.zip.ZipEntry 4import java.util.zip.ZipFile 5 6/* 7 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 8 */ 9 10ext.tasks_version = '16.0.1' 11 12def attr = Attribute.of("artifactType", String.class) 13configurations { 14 aar { 15 attributes { attribute(attr, ArtifactTypeDefinition.JAR_TYPE) } 16 sourceSets.main.compileClasspath += it 17 sourceSets.test.compileClasspath += it 18 sourceSets.test.runtimeClasspath += it 19 } 20} 21 22dependencies { 23 registerTransform { 24 from.attribute(attr, "aar") 25 to.attribute(attr, "jar") 26 artifactTransform(ExtractJars.class) 27 } 28 29 aar("com.google.android.gms:play-services-tasks:$tasks_version") { 30 exclude group: 'com.android.support' 31 } 32} 33 34tasks.withType(dokka.getClass()) { 35 externalDocumentationLink { 36 url = new URL("https://developers.google.com/android/reference/") 37 // This is workaround for missing package list in Google API 38 packageListUrl = projectDir.toPath().resolve("package.list").toUri().toURL() 39 } 40 41 afterEvaluate { 42 classpath += project.configurations.aar.files 43 } 44} 45 46class ExtractJars extends ArtifactTransform { 47 @Override 48 List<File> transform(File input) { 49 unzip(input) 50 51 List<File> jars = new ArrayList<>() 52 outputDirectory.traverse(nameFilter: ~/.*\.jar/) { jars += it } 53 54 return jars 55 } 56 57 private void unzip(File zipFile) { 58 ZipFile zip 59 try { 60 zip = new ZipFile(zipFile) 61 for (entry in zip.entries()) { 62 unzipEntryTo(zip, entry) 63 } 64 } finally { 65 if (zip != null) zip.close() 66 } 67 } 68 69 private void unzipEntryTo(ZipFile zip, ZipEntry entry) { 70 File output = new File(outputDirectory, entry.name) 71 if (entry.isDirectory()) { 72 output.mkdirs() 73 } else { 74 InputStream stream 75 try { 76 stream = zip.getInputStream(entry) 77 Files.copy(stream, output.toPath()) 78 } catch (NoSuchFileException ignored) { 79 } finally { 80 if (stream != null) stream.close() 81 } 82 } 83 } 84} 85