有没有办法将Gradle插件从存储库下载到Gradle缓存并在离线模式下使用它? [英] Is there a way to download a Gradle plugin from the repository to Gradle cache and use it in offline mode?

查看:3095
本文介绍了有没有办法将Gradle插件从存储库下载到Gradle缓存并在离线模式下使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个可在 - offline 模式下工作的gradle项目的副本。我已经将所有步骤都自动化了。我无法自动将插件jar下载到gradle缓存中。

通过指定 GRADLE_USER_HOME ,我可以下载所有依赖项,并将整个gradle缓存与项目捆绑在一起。不幸的是,我们正在使用一些自定义插件。我当然可以为它们中的每一个例外,并且手动包含它们,并且在离线模式下使用某些 if 语句。但是,如果我可以简单地将jar下载到缓存中,这将非常有用。



有没有办法强制gradle下载所有的依赖关系,包括插件依赖关系? p>

这就是我为其他依赖项所做的事情:

 任务resolveAllDependencies {
doLast {
configurations.all {it.resolve()}
}
}

它将所有依赖关系下载到本地缓存。但插件当然不包含在任何配置中。

似乎即使插件已下载到缓存中,它仍会在脱机模式下失败,并显示以下消息:插件无法从 https://plugins.gradle.org/api/gradle ,因为Gradle正在离线模式下运行

解决方案

这是一个可行的解决方案。这并不完美,因为它对gradle插件库进行了硬编码并更改了脚本。它比当前使用插件的方式更加冗长。



而不是以下简单的插件定义:

 插件{
id'net.researchgate.release'version'2.3.5'
}

$ b

可以手动定义资源库和依赖项,然后以这种方式使用插件:

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

这会将插件下载到本地gradle缓存中。


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

解决方案

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.

这篇关于有没有办法将Gradle插件从存储库下载到Gradle缓存并在离线模式下使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆