Skip to content

Instantly share code, notes, and snippets.

@welsh
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save welsh/ddff0ce0a087c82491c2 to your computer and use it in GitHub Desktop.
Save welsh/ddff0ce0a087c82491c2 to your computer and use it in GitHub Desktop.
import java.util.regex.Pattern
apply plugin : SplitCopyDependenciesPlugin
class SplitCopyDependenciesPlugin implements Plugin<Project> {
void apply(Project project) {
project.extensions.create("splitCopyDependencies", SplitCopyDependenciesPluginExtension)
project.task('splitCopyDependencies') << {
def frameworkLib = []
def extLib = []
println ""
println "Building build/frameworkLib and build/extLib directories..."
def pattern = Pattern.quote(System.getProperty("file.separator"))
project.configurations.compile.each { File file ->
project.copy {
from file.absolutePath
def groupIdSplit = file.absolutePath.split(pattern)
def groupId = groupIdSplit[groupIdSplit.length - 5]
if(project.splitCopyDependencies.exactMatch) {
if(groupId.equals(project.splitCopyDependencies.frameworkGroup)) {
frameworkLib.add(file)
into 'build/frameworkLib'
} else {
extLib.add(file)
into 'build/extLib'
}
} else {
if(groupId.contains(project.splitCopyDependencies.frameworkGroup)) {
frameworkLib.add(file)
into 'build/frameworkLib'
} else {
extLib.add(file)
into 'build/extLib'
}
}
}
}
println "Built."
println ""
println "build/frameworkLib Contents:"
frameworkLib.each { File file -> println "\t" + file.name }
println ""
println "build/extLib Contents:"
extLib.each { File file -> println "\t" + file.name }
}
}
}
class SplitCopyDependenciesPluginExtension {
String frameworkGroup
boolean exactMatch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment