This plugin resolves your project dependency artifacts (jar, javadoc, pom, etc.), including transitive ones, and stores them alongside your code. This way you can always build your project without having to fetch dependencies from remote servers.
Tested with Gradle 6.9.1
All Gradle versions:
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'gradle.plugin.io.pry.gradle.offline_dependencies:gradle-offline-dependencies-plugin:0.7.0'
}
}
apply plugin: 'io.pry.gradle.offline_dependencies'
For Gradle >= 2.1:
plugins {
id 'io.pry.gradle.offline_dependencies' version '0.7.0'
}
The plugin creates a local maven repository where all dependency artifacts will be stored for offline use. To use this repository, add the following:
repositories {
maven {
url offlineRepositoryRoot
}
}
The offlineRepositoryRoot
property is set by the plugin and defaults to ${project.projectDir}/offline-repository
.
This property is a standard groovy property and may be changed to whatever path suits your needs. Typically, this location will be somewhere alongside your project and committed to version control.
Next, configure the repositories you want to fetch dependencies from:
offlineDependencies {
repositories {
mavenCentral()
}
}
Currently the plugin only exposes a single task:
> ./gradlew updateOfflineRepository
Downloads dependency artifacts and stores them locally
The offline-dependencies Plugin defines the following properties which may be configured within the offlineDependencies
section:
includeSources
: Download sources (default istrue
)includeJavadocs
: Download javadocs (default istrue
)includePoms
: Download pom.xml artifacts (default istrue
)includeIvyXmls
: Download ivy.xml artifacts (default istrue
)includeBuildscriptDependencies
: Download dependencies defined in thebuildscript
section (default istrue
). Buildscript dependencies need special handling. See Handling Buildscript Dependencies below for detailsconfigurations
: Project configurations for which dependency artifacts should be downloaded (defaults to all project configurations)buildScriptConfigurations
: Buildscript configurations for which dependency artifacts should be downloaded (defaults to all buildscript configurations)
There are two issues when it comes to buildscript dependencies. Both stem from the fact that gradle applies the offline-dependencies
plugin only after the buildscript
block has been evaluated.
The first issue is that you can not use the default offlineRepositoryRoot
property within a buildscript block, the reason being that the offline-dependencies
plugin hasn't had a chance to set the property by itself yet.
You can get around that limitation by setting the property yourself, e.g. by supplying it as a command line parameter:
./gradlew updateOfflineRepository -PofflineRepositoryRoot=./offline-repository
Alternatively you can create an entry for this property in your project's gradle.properties
file.
The second issue is that gradle won't be able to resolve your buildscript dependencies when running the updateOfflineRepository
task for the first time. You can solve this issue by specifying the offline repository alongside the remote repositories, e.g.
buildscript {
repositories {
maven {
url offlineRepositoryRoot
}
maven {
url 'https://plugins.gradle.org/m2/'
}
mavenCentral()
jcenter()
}
dependencies {
classpath 'gradle.plugin.io.pry.gradle.offline_dependencies:gradle-offline-dependencies-plugin:0.5.0'
classpath 'some.other.buildscript:dependency:1.0.0'
}
}
offlineDependencies {
repositories {
// You'll have to add your buildscript repositories here too
maven {
url 'https://plugins.gradle.org/m2/'
}
mavenCentral()
jcenter()
}
includeSources = true
includeJavadocs = true
includePoms = true
includeIvyXmls = true
includeBuildscriptDependencies = true
}
Just make sure that the offlineRepositoryRoot
repository is first in the list.
apply plugin: 'io.pry.gradle.offline_dependencies'
apply plugin: 'java'
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath "gradle.plugin.io.pry.gradle.offline_dependencies:gradle-offline-dependencies-plugin:0.5.0"
}
}
repositories {
maven {
url offlineRepositoryRoot
}
}
offlineDependencies {
repositories {
ivy {
url 'http://archiecobbs.github.io/ivyroundup/repo/modules/'
layout 'pattern', {
artifact '[organisation]/[module]/[revision]/packager.xml'
ivy '[organisation]/[module]/[revision]/ivy.xml'
}
}
mavenCentral()
}
includeSources = true
includeJavadocs = true
includePoms = true
includeIvyXmls = true
includeBuildscriptDependencies = false
configurations 'compile', 'debug'
buildScriptConfigurations 'classpath'
}
version = '1.0'
sourceCompatibility = 1.8
dependencies {
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.1'
compile 'com.google.guava:guava:19.0'
}