gradle没有在mavenLocal repo中找到jar

时间:2015-03-07 03:02:39

标签: spring maven gradle ivy

我依赖于spring-beans; 4.0.0.RELEASE,我使用

安装到我的mavenLocal缓存中

mvn install:install-file -Dfile=/Users/jric/Downloads/spring-beans-4.0.0.RELEASE.jar -DpomFile=/Users/jric/Downloads/spring-beans-4.0.0.RELEASE.pom

但gradle-1.11未能找到依赖项,没有太多解释。我确实找到了这个相关的堆栈跟踪:

11:26:35.432 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainDependencyResolver] Discarding resolve failure.
java.lang.NullPointerException
        at org.gradle.api.internal.artifacts.repositories.resolver.MavenLocalResolver.isOrphanedPom(MavenLocalResolver.java:49)
        at org.gradle.api.internal.artifacts.repositories.resolver.MavenLocalResolver.findMetaDataArtifact(MavenLocalResolver.java:42)
        at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.resolveStaticDependency(ExternalResourceResolver.java:165)
        at org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver.getDependency(MavenResolver.java:83)
        at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.LocalModuleVersionRepository.getLocalDependency(LocalModuleVersionRepository.java:44)
        at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.memcache.CachedRepository.getLocalDependency(CachedRepository.java:67)

这里有一些可能相关的数据:

SCML-JRichardson:share jric$ ls /Users/jric/.m2/repository/org/springframework/spring-beans/
4.0.0.RELEASE           maven-metadata-local.xml
SCML-JRichardson:share jric$ cat /Users/jric/.m2/repository/org/springframework/spring-beans/maven-metadata-local.xml 
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
  <versioning>
    <release>4.0.0.RELEASE</release>
    <versions>
      <version>4.0.0.RELEASE</version>
    </versions>
    <lastUpdated>20150307021047</lastUpdated>
  </versioning>
</metadata>
SCML-JRichardson:share jric$ ls /Users/jric/.m2/repository/org/springframework/spring-beans/4.0.0.RELEASE/
_maven.repositories     spring-beans-4.0.0.RELEASE.jar  spring-beans-4.0.0.RELEASE.pom

1 个答案:

答案 0 :(得分:5)

Gradle有一个特殊的声明来查看本地Maven存储库:mavenLocal()。确保在全局存储库部分中调用它:

repositories {
    mavenLocal()  // <- Here
    mavenCentral()
}

如果它不起作用,请确保您没有在buildscript部分中无意中添加它。这会将依赖性添加到构建环境而不是代码中,这通常不是您想要的。

buildscript {            // <- Probably not what you mean
    repositories {
        mavenLocal()
        mavenCentral()
    }
}