Skip to content

Instantly share code, notes, and snippets.

@ozodrukh
Last active August 29, 2015 14:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ozodrukh/0e4a4a2f44891d9cef74 to your computer and use it in GitHub Desktop.
[Gradle] Add square dependecies
//usage in modules just add
dependencies {
addSquareUpArtifacts ":app", 'retrofit', '1.9.0', 'okhttp', '2.3.0'
}
/**
* Some more utility methods,
* ! Paste it in root build.gradle
*/
project.ext{
/**
* For each method that will pass 2 arguments from an array
* by formula kn+1 where k = 2, and n is position of loop
*
*/
forEachWithKNp1 = { String[] items, Closure op ->
final int length = items.length / 2;
final int k = 2;
for(int index = 0; index < length; index++){
op(items[k*index], items[k*index + 1]);
}
}
/**
* Adds square dependencies in {@code projectPath}, which was enumerated
* in {@code names} argument
*/
addSquareUpArtifacts = {String projectPath, String... names ->
final Project target = project.project(projectPath)
forEachWithKNp1(names, { name, version ->
println "com.squareup.$name:$name:$version"
target.getDependencies().add('compile', "com.squareup.$name:$name:$version")
})
}
addSupportLibraries = {String projectPath, String... names ->
final Project target = project.project(projectPath)
forEachWithKNp1(names, { name, version ->
target.getDependencies().add('compile', "com.android.support:$name:$version")
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment