简体   繁体   English

如何从本地 Maven 存储库中选择依赖项

[英]How to pick a dependency from local Maven repository

I've published a dependency locally.我已经在本地发布了一个依赖项。 The dependency is located on path依赖项位于路径上

C:\Users\myusername\.m2\repository\com\mycompany\my-library\1.0\*

which I think is the default path on Windows.我认为这是 Windows 上的默认路径。

Now, on a different project I try to consume this library.现在,在另一个项目中,我尝试使用这个库。 My build.gradle looks like this(among other dependencies)我的build.gradle看起来像这样(在其他依赖项中)

...
buildscript {
  repositories {
     mavenLocal()
  }
}
...
dependencies {
   implementation('com.mycompany:my-library:1.0')
}

I'm getting build errors that some classes do not exist etc...我收到一些类不存在等的构建错误......

Shouldn't this be enough to identify the dependency from local repository?这还不足以从本地存储库中识别依赖关系吗?

I also use a remote repository for other dependencies but the artifact name+version is unique(com.mycompany:my-library:1.0).我还为其他依赖项使用远程存储库,但工件名称+版本是唯一的(com.mycompany:my-library:1.0)。 I would expect to find this dependency from the local repository.我希望从本地存储库中找到这种依赖关系。 Instead, I'm getting build errors that some classes do not exists etc...相反,我得到了一些类不存在等的构建错误......

EDIT:编辑:

The classes should be in the aforementioned library.这些类应该在上述库中。 I used ./gradlew publishToMavenLocal to publish the library locally, and I can see that it's there.我使用./gradlew publishToMavenLocal在本地发布库,我可以看到它在那里。 Is is generated with the correct version etc..是使用正确的版本等生成的。

The buildscript block configures the configuration of the gradle build itself. buildscript 块配置 gradle 构建本身的配置。 So by declaring the repositories in it, you are only affecting the buildscript.因此,通过在其中声明存储库,您只会影响构建脚本。 Try it outside of the buildscript在构建脚本之外buildscript

repositories {
     mavenLocal()
}


dependencies {
   implementation('com.mycompany:my-library:1.0')
}

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

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