首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Github包中安装maven依赖项?

如何从Github包中安装maven依赖项?
EN

Stack Overflow用户
提问于 2021-11-19 12:14:02
回答 1查看 985关注 0票数 0

我在Github包中创建了一个maven依赖项。我正在尝试在我的另一个骡子项目中安装这个依赖项。

settings.xml:

代码语言:javascript
复制
<server>
    <id>github</id>
    <username><owner></username>
    <password><Token></password>
</server>

<profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
          <id>github</id>
          <url>https://maven.pkg.github.com/<owner>/<repo-name></url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
          <releases>
            <enabled>true</enabled>
          </releases>
        </repository>
      </repositories>
    </profile>
  </profiles>

来自Github包的依赖关系:

代码语言:javascript
复制
<dependency>
  <groupId>com.mycompany</groupId>
  <artifactId>hello-world-3</artifactId>
  <version>1.0.11-SNAPSHOT</version>
</dependency>

我创建了hello应用程序,并在Pom.xml中添加了依赖项,并在命令提示符下运行mvn。

获取此错误:

代码语言:javascript
复制
D:\WorkSpace\test-package-dependency>mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.mycompany:test-package-dependency >----------------
[INFO] Building test-package-dependency 1.0.0-SNAPSHOT
[INFO] --------------------------[ mule-application ]--------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.845 s
[INFO] Finished at: 2021-11-19T17:21:57+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project test-package-dependency: Could not resolve dependencies for project com.mycompany:test-package-dependency:mule-application:1.0.0-SNAPSHOT: Failure to find com.mycompany:hello-world-3:jar:1.0.11-SNAPSHOT in https://maven.anypoint.mulesoft.com/api/v2/maven was cached in the local repository, resolution will not be reattempted until the update interval of anypoint-exchange-v2 has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

我已经在网上搜索过了,但是我的错误并没有得到解决。还有,试过了。也没什么用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-19 23:02:52

您必须在您想要访问的项目的 pom.xml中定义访问存储库url。

只需定义如下,

代码语言:javascript
复制
<repositories>
    <repository>
      <id>central</id>
      <url>https://repo1.maven.org/maven2</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </repository>
    <repository>
      <id>github</id>
      <url>https://maven.pkg.github.com/<owner>/<repo-name></url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </repository>
  </repositories>

或者只尝试使用id和url。

代码语言:javascript
复制
<repositories>
    <repository>
      <id>central</id>
      <url>https://repo1.maven.org/maven2</url>
    </repository>
    <repository>
      <id>github</id>
      <url>https://maven.pkg.github.com/<owner>/<repo-name></url>
    </repository>
  </repositories>

注意:确保您有权限读取或下载jar,以便Maven可以在运行maven阶段时轻松地为您下载。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70034672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档