简体   繁体   English

Gradle将依赖项下载到缓存而不是maven存储库

[英]Gradle downloading dependency into cache instead of maven repository

I am trying to maintain the same repository on my filesystem for maven and gradle. 我试图在我的文件系统上为maven和gradle维护相同的存储库。 But I am running into some problems. 但是我遇到了一些问题。

I have the following in my build.gradle file. 我在build.gradle文件中有以下内容。

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.3.9'
    runtime group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.3.9'
    runtime 'org.xerial:sqlite-jdbc:3.8.7'
}

GRADLE_HOME is D:\\Programming\\Java\\gradle-2.2.1 GRADLE_HOME是D:\\Programming\\Java\\gradle-2.2.1
GRADLE_USER_HOME is D:\\Programming\\Java\\.m2 GRADLE_USER_HOME是D:\\Programming\\Java\\.m2

My gradle home is the same as my Maven repository. 我的gradle home与我的Maven存储库相同。

But when the dependencies are downloaded via gradle they are being downloaded into the GRADLE_USER_HOME\\cache instead of the repository folder. 但是当通过gradle下载依赖项时,它们将被下载到GRADLE_USER_HOME\\cache而不是repository文件夹中。 What configuration am I missing? 我错过了什么配置?

EDIT I have checked the chapter on dependency management of the book Gradle In Action . 编辑我已经检查了Gradle In Action一书的依赖管理章节。 Nothing. 没有。 I have checked the dependency management on gradle's website but it also just says that cache is used. 我已经检查了gradle网站上的依赖关系管理 ,但它也只是说使用了缓存。

It seems that there is no such option available in gradle. 似乎gradle中没有这样的选项。 Can someone confirm? 有人可以证实吗?

There is no setting to change that. 没有设置可以改变它。 There is no gradle repository as such. 这样没有gradle存储库。 Also, it seems like a bad idea to have gradle use the repository's folder as dependency cache because of the clutter. 此外,由于杂乱,让gradle使用存储库的文件夹作为依赖缓存似乎是一个坏主意。

If you are trying to publish artifacts built by gradle to said maven repository, you should probably take a look at the maven-publish plugin. 如果您尝试将gradle构建的工件发布到所述maven存储库,那么您应该查看maven-publish插件。

If you are trying to use artifacts from that repository in your build, the way to go would be to add mavenLocal() to your repositories and then just use the compile function in your dependencies. 如果您尝试在构建中使用该存储库中的工件,那么可以采用的方法是将mavenLocal()添加到您的存储库,然后只使用依赖项中的compile函数。

Yes, I read the source code and just confirmed There is no setting to change that. 是的,我阅读了源代码并且刚刚确认没有设置可以更改它。

Here is my solution: 这是我的解决方案:

  1. install a local maven repository manager like Nexus. 安装像Nexus这样的本地maven存储库管理器。

  2. config gradle using that repository. config gradle使用该存储库。

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

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