Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.raizlabs:Griddle:'
}
dependencies {
implementation("com.github.raizlabs:Griddle:")
}
<dependency>
<groupId>com.github.raizlabs</groupId>
<artifactId>Griddle</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.raizlabs" % "Griddle" % ""
:dependencies [[com.github.raizlabs/Griddle ""]]
A powerful dependency management solution for Android/Java-based gradle build environments. It drastically reduces the complexity of build.gradle
files while providing powerful and flexible dependency resolution on top of normal Gradle. It handles linking remote sources for you automatically.
Add the following block to your buildscript.repositories{}
block in the project-level build.gradle
buildscript {
repositories {
mavenCentral()
maven { url "https://raw.github.com/Raizlabs/maven-releases/master/releases" }
}
dependencies {
....
classpath 'com.raizlabs:Griddle:1.0.3'
}
}
// this should come after 'com.android.library' or 'com.android.application
apply plugin: 'com.raizlabs.griddle'
This library uses gradle properties to determine where to search for the dependencies. For example:
griddle_default_group
: The group to resolve dependencies without a specified artifact equivalent when simply specifying a name for the dependency.
griddle_default_library_directory
: The default directory to resolve local submodules in. Default is ":Libraries"
griddle_default_library_extension
: The default extension on dependencies when simply specifying a name for the dependency and the local version is not found. Default is empty. You can specify something like @aar
or @jar
if needed.
Add these variables to your global ~/.gradle/gradle.properties
file, or in project-level gradle.properties file.
mod()
+ nsMod()
jar()
The mod()
and nsMod()
functions are a wrapper around a compile
statement and provides the following:
sources.jar
to a remote dependency
mod 'com.raizlabs.android:Parser:1.2.0'
mod 'com.raizlabs.android:{DBFlow-Core, DBFlow}:1.4.2'
mod 'Parser'
mod 'com.raizlabs.android:{Parser, :Parser:Parser}:1.2.0'
Many times in projects we have a list of dependencies that we utilize and they either specify a remote or local dependency. To simplify this process and enable us to dynamically switch between local and remote as needed, this plugin provides you with a very simple and powerful way such that you will never need to modify your projects build.gradle
.
Dependency resolution for local vs. remote is determined if a project exists in the settings.gradle
. Aiding in that aspect is the griddle_default_library_directory
that will help specify its location when we omit the directory prefix in a mod()
or nsMod()
statement.
You can specify different names for local vs. remote by specifying the following:
mod 'artifactId:{{moduleName, localModuleName}}:version'
mod 'artifactId:{{moduleName, localModuleName}, {anotherModuleName, anotherLocalName}}:version'
Surprisingly enough, the standard compile
statement in Gradle does not enable attaching sources to the remote dependency easily. Also, to note, we do not want to have to manually attach sources every time we update a dependency and ensure that those sources are the correct one.
By using the mod()
function, sources will automatically get attached. Note: not all dependencies have sources, so if it fails to discover a sources.jar
use nsMod()
(no-source module) instead.
For multiple dependencies coming from the same repo that all have to share the same version, previously we had to do something like this:
dependencies {
compile 'com.google.android.gms:play-services-maps:6.5.87'
compile 'com.google.android.gms:play-services-location:6.5.87'
compile 'com.google.android.gms:play-services-plus:6.5.87'
compile 'com.google.android.gms:play-services-fitness:6.5.87'
}
Every time we want to update, we have to painstakingly change each one. Using the mod()
or nsMod()
(for this example), we can move this declaration to one line.
dependencies {
nsMod 'com.google.android.gms:{play-services-maps, play-services-location, play-services-plus, play-services-fitness}:6.5.87'
}
Using the mod
or nsMod
in this format: mod 'groupId:artifactName:artifactVersion'
you can:
{}
around the artifactName
and add more similar artifacts separated by commas. If you place one or more of the comma-separated items in {}
, you can specify remote vs local such like:mod 'com.raizlabs.android:{BaseUtils, {WebServiceManager, :WebServiceManager:WebServiceManager}}:1.0.0'
{}
around the artifactVersion
and specify a per-dependency version. Note the length of comma-separated artifactNames
must match the versions specified.compileDebug
) name to the end of the function:mod 'groupId:artifactName:artifactVersion', 'compileDebug'
Note any artifact specified this way will automatically utilize the next feature of this library. If there is a local version available in the settings.gradle
by combining these properties:
Specifying in this format: mod 'artifactName'
:
1. Utilizes the griddle_default_group
if the local version is missing
2. Utilizes griddle_default_library_directory
to find the local version of this repo
3. Uses the griddle_default_library_extension
if local version is missing by appending it to create the
compile 'groupId:artifactName:artifactVersion{extension}'
For specifying a jar dependency, we usually specify it this way:
dependencies {
compile files('libs/android-support-v4.jar', 'libs/http-master-1.0.6.jar')
}
For a much cleaner approach, with this plugin we can use:
dependencies {
jar 'android-support-v4'
jar 'http-master-1.0.6'
}
The jar()
method will automatically append libs
and .jar
to the dependency to clean up the look of the file. If you need all jars, use the method jars()
to mimic the compile fileTree("libs", include: "*.jar")