我想使用本地计算机上的缓存 Artifact 的 Maven 存储库,通过避免下载它们来加速 Gradle 构建。
不幸的是,我注意到即使首先列出了本地存储库并且它具有我需要的依赖项,但如果 Internet 连接可用,Gradle 将从 Internet 获取 Artifact ,并且仅在获取问题时才使用本地存储库到网络一。
这是一个重现此问题的具体小示例:
build.gradle :
apply plugin: 'java'
repositories {
maven {
name 'cache'
url "/home/vagrant/m2copy"
}
jcenter()
}
dependencies {
compile 'com.google.code.gson:gson:2.4'
}
jar {
manifest {
attributes 'Created-By': 'Ekumen'
}
}
的内容/home/vagrant/m2copy :
m2copy:
com
m2copy/com:
google
m2copy/com/google:
code
m2copy/com/google/code:
gson
m2copy/com/google/code/gson:
gson
m2copy/com/google/code/gson/gson:
2.4
m2copy/com/google/code/gson/gson/2.4:
gson-2.4.jar
gson-2.4.jar.sha1
_remote.repositories
以及 gradle 构建的输出:
vagrant@vagrant-ubuntu-trusty-64:~/test_cache$ ./gradlew build
:compileJava
Download https://jcenter.bintray.com/com/google/code/gson/gson/2.4/gson-2.4.pom
Download https://jcenter.bintray.com/org/sonatype/oss/oss-parent/9/oss-parent-9.pom
Download https://jcenter.bintray.com/com/google/code/gson/gson/2.4/gson-2.4.jar
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
有什么想法为什么 Gradle 在这种情况下会跳过本地存储库,并且仅在无法访问 jcenter 时才使用它?
最佳答案
我相信您可能会丢失缓存中的 .pom 描述 rune 件以及其他一些 .xml 描述符。尝试为您的依赖项获取 .pom 文件,看看是否有帮助。
关于maven - 让 Gradle 使用本地 Maven 存储库中的 Artifact ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35213585/