【问题标题】:Gradle Offline Build Using Maven Repository使用 Maven 存储库进行 Gradle 离线构建
【发布时间】:2019-01-09 14:33:16
【问题描述】:

我正在尝试设置离线 Gradle 构建。

理想情况下,我希望将我的所有项目依赖项都放在一个任意 maven 存储库中,如下所示:

repositories {
    maven {
        url 'file://PATH/TO/REPO'
    }
}

但是,在全新的 Gradle 安装(没有 ~/.gradle 缓存)中,上述操作失败了:

* What went wrong
Plugin [id: PLUGINID, version: PLUGINVERSION] was not found in any of the 
following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolvee plugin artifact     'PLUGINID:PLUGINNAME:PLUGINVERSION')
    Searched in the following repositories: 
        Gradle Central Plugin Repository 

我尝试了几种不同的方法来指定存储库,包括:

  1. 将“url...”替换为“flatDir { dir '/PATH/TO/REPO' }”。
  2. 将所有依赖项复制到 ~/.m2 并调用 mavenLocal() 作为存储库。

要将依赖项从 ~/.gradle/caches/modules-2/files-2.1/ 复制到我的“离线”存储库中,我尝试过:

  1. 直接复制/粘贴
  2. 一个将结构转换成这样的 Gradle 任务:

    task cacheLocal(type: Copy) {
        from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1')
        into '/PATH/TO/REPO'
        eachFile {
            List<String> parts = it.path.split('/')
            it.path = (parts[0] + '/' + parts[1]).replace('.','/') + '/' + parts[2] + '/' + parts[4]
        }
        includeEmptyDirs = false
     }
    

其他:

  • 使用“--offline”运行没有区别。
  • 如果 ~/.gradle 已经存在,则构建成功,否则失败。

我的插件块(上面的错误语句会打到第一个非Gradle核心插件,所以在这种情况下是protobuf):

plugins {
    id "com.google.protobuf" version "0.8.6"
    id "nebula.ospackage" version "4.9.3"
    id "java"
    id "eclipse"
}

这超出了我的深度,任何帮助将不胜感激!

【问题讨论】:

  • 这与repositories 块无关,但与plugins 块有关。你能把它添加到你的问题中吗?
  • @lu.koerfer 我在上面添加了插件块。据我了解,尽管在 --offline 模式下运行并且插件已经存在于本地离线存储库中,但 Gradle 似乎正在尝试访问网络以下载 protobuf 插件(我猜它没有捡起它,但不确定我将如何检查故障发生的位置)。感谢您提供的任何帮助。

标签: java android maven gradle groovy


【解决方案1】:

如果您还希望从本地存储库中解析插件,则必须配置 pluginManagement 部分来执行此操作。 在您的问题中,您似乎只配置了项目存储库。

example in the documentation

【讨论】:

  • 谢谢!我不知道有分离。
猜你喜欢
  • 1970-01-01
  • 2017-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-28
  • 2021-04-12
  • 2019-02-06
  • 2018-02-12
相关资源
最近更新 更多