[Gradle] Add square dependecies
This file contains 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
//usage in modules just add | |
dependencies { | |
addSquareUpArtifacts ":app", 'retrofit', '1.9.0', 'okhttp', '2.3.0' | |
} |
This file contains 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
/** | |
* 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