本文介绍了Gradle:是否可以发布到Gradle自己的本地缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以结合使用maven插件和mavenLocal()来安装工件并在本地使用.

I know that I can use the maven plugin coupled with mavenLocal() to install an artifact and use it locally.

但是,对此进行进一步的调查,我注意到这意味着工件已安装到Mavens的标准~/.m2中,但同时Gradle自己的缓存以不同的格式存在于~/.gradle/caches下.

However investigating this a bit further, I notice that this means the artifacts are installed to Mavens's standard ~/.m2, but at the same time Gradle's own cache lives under ~/.gradle/caches in a different format.

这对我来说似乎很浪费,a)使用两个本地缓存,b)必须将mavenLocal()添加到所有项目.我想知道是否可以将工件发布到Gradle的~/.gradle/caches吗?

This seems wasteful to me, a) working with two local caches, and b) having to add mavenLocal() to all projects. I was wondering if there is a way to publish an artifact to Gradle's ~/.gradle/caches ?

推荐答案

请注意,本地Maven存储库不是(真的)缓存,并且Gradle缓存不是存储库. Gradle仅使用其缓存来缓存远程工件,它不应复制从本地Maven存储库中检索到的工件.反过来,您无法将工件发布到Gradle缓存.

Note that the local Maven repository is not (really) a cache, and that the Gradle cache is not a repository. Gradle uses its cache only to cache remote artifacts, it should not copy artifacts retrieved from local Maven repositories there. In turn, you cannot publish artifacts to the Gradle cache.

因此,发布和使用mavenLocal()的方法不应像您想象的那样浪费.同样,您不必将mavenLocal()单独添加到多项目的所有项目中.您可以在根项目中简单地使用allprojects { repositories { mavenLocal() } }之类的东西.或者,如果您想在 all 中的mavenLocal()中创建独立的Gradle项目,甚至可以尝试将其添加到~/.gradle/init.gradle.

So the approach to publish to and use mavenLocal() should not be as wasteful as you think. Also, you do not have to add mavenLocal() to all projects of a multi-project separately. You can simply use something like allprojects { repositories { mavenLocal() } } in your root project. Or if you want mavenLocal() in all your independent Gradle projects you could even try adding it to ~/.gradle/init.gradle.

这篇关于Gradle:是否可以发布到Gradle自己的本地缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 08:35