简体   繁体   English

使用Maven存储库进行Gradle离线构建

[英]Gradle Offline Build Using Maven Repository

I'm attempting to setup an offline Gradle build. 我正在尝试设置离线Gradle构建。

I would ideally like to have all my project dependencies in an arbitrary maven repository referenced as below: 理想情况下,我希望将我所有的项目依赖项放在任意引用的Maven存储库中,如下所示:

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

However, the above fails in a fresh Gradle install (no ~/.gradle cache) with the following: 但是,以上内容在全新的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 

I've tried a few different ways to specify the repository, including: 我尝试了几种不同的方法来指定存储库,包括:

  1. Replacing "url..." with "flatDir { dir '/PATH/TO/REPO' }". 用“ flatDir {dir'/ PATH / TO / REPO'}”替换“ url ...”。
  2. Copying all dependencies to ~/.m2 and calling mavenLocal() as the repository. 将所有依赖项复制到〜/ .m2并调用mavenLocal()作为存储库。

To copy dependencies from ~/.gradle/caches/modules-2/files-2.1/ into my "offline" repository, I have tried: 要将依赖项从〜/ .gradle / caches / modules-2 / files-2.1 /复制到我的“离线”存储库中,我尝试过:

  1. Straight copy/paste 直拷贝/粘贴
  2. A Gradle task which converts the structure as such: 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 } 

Other things: 其他事情:

  • Running with "--offline" makes no difference. 使用“ --offline”运行没有区别。
  • Build is successful if ~/.gradle is already present, but fails otherwise. 如果〜/ .gradle已经存在,则构建成功,但否则失败。

My plugins block (the above error statement will hit the first non-Gradle core plugin, so protobuf in this case): 我的插件块(上面的错误声明将命中第一个非Gradle核心插件,因此在这种情况下为protobuf):

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

This is out of my depth and any help would be greatly appreciated! 这超出了我的理解范围,任何帮助将不胜感激!

If you want also plugins to be resolved from a local repository, you have to configure the pluginManagement section to do so. 如果还希望从本地存储库解析插件,则必须配置pluginManagement部分来执行此操作。 In your question, it looks like you only configured project repositories. 在您的问题中,您似乎只配置了项目存储库。

See the example in the documentation 请参阅文档中示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM