Created
June 29, 2020 22:00
-
-
Save jbruchanov/41195446ae9fc722c8b499bf0211c94b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static def isAndroidApp(Project project) { | |
return project.plugins.findPlugin("com.android.application") != null | |
} | |
private static def isJavaLib(Project project) { | |
return project.plugins.findPlugin("java-library") != null | |
} | |
class ProjectDetails { | |
ProjectDetails(classDirs, srcDirs, buildDir, testTask) { | |
this.classDirs = classDirs | |
this.srcDirs = srcDirs | |
this.buildDir = buildDir | |
this.testTask = testTask | |
} | |
Collection<String> classDirs | |
Collection<String> srcDirs | |
String buildDir | |
Task testTask | |
} | |
private static def getSourceAndOutputFolders(Project rootProject, String androidVariant) { | |
def variantName = androidVariant | |
def result = rootProject.subprojects.collectEntries { project -> | |
def data | |
//each project, first line in build.gradle | |
if (isJavaLib(project)) { | |
def srcDirs = project.sourceSets.main.java.srcDirs | |
def javaClassesDir = project.tasks.getByName("compileJava").destinationDir | |
def kotlinClassesDir = project.tasks.getByName("compileKotlin").destinationDir | |
data = new ProjectDetails([javaClassesDir, kotlinClassesDir], srcDirs, project.buildDir.absolutePath, project.tasks.getByName("test")) | |
} else { | |
def variant = (isAndroidApp(project) | |
? project.android.applicationVariants | |
: project.android.libraryVariants) | |
.findAll { it.name == variantName } | |
.first() | |
def vCap = variant.name.capitalize() | |
def javaClassesDir = project.tasks.getByName("compile${vCap}Kotlin").destinationDir | |
def kotlinClassesDir = project.tasks.getByName("compile${vCap}JavaWithJavac").destinationDir | |
def srcDirs = variant.sourceSets.java.srcDirs.flatten() | |
data = new ProjectDetails([javaClassesDir, kotlinClassesDir], srcDirs, project.buildDir.absolutePath, project.tasks.getByName("test${vCap}UnitTest")) | |
} | |
[(project.name): data] | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment