简体   繁体   English

使Gradle使用Maven本地存储库下载工件

[英]Make Gradle use Maven local repository for downloading artifacts

I know I can configure Gradle to use local Maven repository 我知道我可以配置Gradle以使用本地Maven存储库

repositories {
    mavenLocal()
    mavenCentral()
}

Can I configure Gradle to download into Local (maven) repository? 我可以配置Gradle下载到本地(Maven)存储库吗? (So that Maven would also be able to use those jars) (这样Maven也可以使用这些jar)

ref Gradle configuration to use maven local repository ref Gradle配置以使用Maven本地存储库

A solution was given in the gradle forums: https://discuss.gradle.org/t/need-a-gradle-task-to-copy-all-dependencies-to-a-local-maven-repo/13397/2 在gradle论坛中提供了一个解决方案: https ://discuss.gradle.org/t/need-a-gradle-task-to-copy-all-dependencies-to-a-local-maven-repo/13397/2

using this gradle plugin: https://github.com/ysb33r/ivypot-gradle-plugin you can call a new tasg 使用此gradle插件: https : //github.com/ysb33r/ivypot-gradle-plugin您可以调用新的tasg

gradle syncRemoteRepositories

which will download all dependencies to a local Ivy repository (which is the same library Maven uses). 它将所有依赖项下载到本地Ivy存储库(与Maven使用的库相同)。 The folder you point to with 您指向的文件夹

syncRemoteRepositories {
   repoRoot '/path/to/repo'
}

will contain the dependencies. 将包含依赖项。 I would suggest first trying out with a different local path than your M2_HOME, because I saw some warning about the Ivy repository structure having changed between Maven versions. 我建议先尝试使用不同于M2_HOME的本地路径,因为我看到一些关于Ivy存储库结构在Maven版本之间更改的警告。

It should be as simple as 它应该像

apply plugin: 'maven'
apply plugin: 'java'
dependencies {
    mavenLocal()
}        

And

gradle install

More info here 更多信息在这里

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

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