Gradle不使用Maven Local Repository作为新的依赖项 [英] Gradle does not use the Maven Local Repository for a new dependency
问题描述
我将Maven与M2_HOME定义为: 我有位于以下位置的settings.xml文件: 其中我声明如下: 到此为止,Maven一切正常。任何新的依赖关系都会去那里。 我有一个基于Gradle的项目,在我的build.gradle中有很多东西,存在以下几种:
$ b
< localRepository> / Users / manuelj / apache / maven / repository< / localRepository>
apply plugin:'java'
apply plugin:'maven'
apply plugin:'eclipse'
apply plugin:'应用程序'
version ='1.0.0'
sourceCompatibility ='1.8'
存储库{
mavenLocal()
mavenCentral()
}
...更多
直到这里,所有的工作都很好。代码编译,执行得很好。
我的困惑如下。根据我的理解,Gradle的 mavenLocal()
应该使用与Maven的 settings.xml中定义的
< localRepository>
相同的路径
现在确认在Maven本地资源库中存在一些已经下载的依赖项。
当我执行gradle build时,我确实意识到如果Maven Local Repository已经存在依赖关系,那么它就是
/Users/manuelj/.gradle/caches/modules -2 / files-2.1
我希望新的依赖直接进入相同的Maven Local Repository 。
因此,需要额外的配置吗?
Gradle的外观转换为
〜/ .m2 / settings.xml
,以获取本地Maven存储库所在的位置信息。如果没有找到任何信息,它会假定〜/ .m2 / repository
。
这是对 mavenLocal() - Gradle如何解析本地Maven仓库的目录?在Gradle论坛上。
引用的讨论还包含针对您的特定问题的解决方案。为了使用非标准的本地maven仓库,您可以在 build.gradle
中使用以下配置:
存储库{
maven {
url'/ Users / manuelj / apache / maven / repository'
}
}
I have Maven with M2_HOME defined to:
- /Users/manuelj/apache/maven/3.2.5
I have the settings.xml file, located on:
- /Users/manuelj/apache/maven/3.2.5/conf/settings.xml
where I have the following declared:
<localRepository>/Users/manuelj/apache/maven/repository</localRepository>
Until here with Maven all works fine. Any new dependency goes there.
I have a project based with Gradle, among many things in my build.gradle, exists the following:
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'application'
version = '1.0.0'
sourceCompatibility = '1.8'
repositories {
mavenLocal()
mavenCentral()
}
… more
Until here, all works fine too. Code compile, executes well.
My confusion is the following.
According with my understanding is that Gradle's mavenLocal()
should use the same path than <localRepository>
defined on Maven's settings.xml
file.
Now confirming that in the Maven local repository exists some dependencies already downloaded.
When I execute for example gradle build, I did realize that
- If a dependency already exists from the Maven Local Repository, it is used from there.
- If a dependency does not exists from the Maven Local Repository Gradle download the new dependency to:
/Users/manuelj/.gradle/caches/modules-2/files-2.1
I want that the new dependency go directly to the same Maven Local Repository.
Therefore, what extra configuration is need it?
mavenLocal()
is resolved like this:
Gradle looks into
~/.m2/settings.xml
for information where the local Maven repository is located. If no information is found, it assumes~/.m2/repository
.
This is an answer to the question "mavenLocal() - how does Gradle resolve the directory of the local maven repository?" given on the Gradle forums.
The referenced discussion also contains a solution for your specific problem. In order to make use of a non-standard local maven repository, you can use the following configuration in your build.gradle
:
repositories {
maven {
url '/Users/manuelj/apache/maven/repository'
}
}
这篇关于Gradle不使用Maven Local Repository作为新的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!