Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to download a Gradle plugin from the repository to Gradle cache and use it in offline mode?

Tags:

gradle

offline

I am trying to create a copy of a gradle project that will work in --offline mode. I have automated all steps apart from one. I am not able to automatically download plugin jars into gradle cache.

My offline distribution works by specifying the GRADLE_USER_HOME, downloading all dependencies and bundling the whole gradle cache with the project. Unfortunately we are using a few custom plugins. I could of course make an exception for each one of them and include them manually, with some kind of if statement for the offline mode. But it would be great if I could simply download the jars into the cache.

Is there a way to force gradle to download all dependencies, including the plugin dependencies?

This is what I am doing for the rest of the dependencies:

task resolveAllDependencies {
    doLast {
        configurations.all { it.resolve() }
    }
}

It downloads all dependencies to the local cache. But plugins are of course not included in any of the configurations.

It also seems that even if the plugin gets downloaded in the cache, it still fails in offline mode with the following message: Plugin cannot be resolved from https://plugins.gradle.org/api/gradle because Gradle is running in offline mode

like image 259
MartinTeeVarga Avatar asked Mar 10 '23 02:03

MartinTeeVarga


1 Answers

Here's a working solution. It's not perfect, because it hard-codes the gradle plugin repository and changes the script. It's also much more verbose than the current way of using plugins.

Instead of the following simple plugin definition:

plugins {
    id 'net.researchgate.release' version '2.3.5'
}

It's possible to define both the repository and the dependency manually and then use the plugin this way:

buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'net.researchgate:gradle-release:2.3.5'
    }
}
apply plugin: 'net.researchgate.release'

This downloads the plugin into the local gradle cache.

like image 177
MartinTeeVarga Avatar answered Apr 09 '23 17:04

MartinTeeVarga