首页 > 解决方案 > 如何在 maven 中使用“dependency:get”插件修复“未授权”错误

问题描述

当我在命令行上使用“dependency:get”插件时,maven 会抛出“未授权”错误。我该如何解决?

我试图在 .m2/settings.xml 中添加我的服务器存储库。我的用户名和密码是正确的。我尝试使用相同的工件和存储库,可以通过 IntelliJ 中的 pom.xml 下载。

这是我的 Maven 命令行,它失败了:

mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get \
-Dartifact=mygroup:myartifact:myversion:aar \
-DremoteRepositories=public::default::my.repository 

.m2/setting.xml

  <servers>
    <server>
      <id>public</id>
      <username>myuser</username>
      <password>mypassword</password>
    </server>
  </servers>

.m2/plugin-registry.xml

<?xml version="1.0" encoding="UTF-8"?>
<pluginRegistry xsi:schemaLocation="http://maven.apache.org/PLUGIN_REGISTRY/1.0.0 http://maven.apache.org/xsd/plugin-registry-1.0.0.xsd"
xmlns="http://maven.apache.org/PLUGIN_REGISTRY/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <useVersion>3.1.1</useVersion>
      <rejectedVersions/>
    </plugin>
 </plugins>
</pluginRegistry>


我的 pom.xml,它成功了:

<dependency>
        <groupId>mygroup</groupId>
        <artifactId>myartifact</artifactId>
        <version>myversion</version>
        <type>aar</type>
</dependency>

<repositories>
        <repository>
            <id>public</id>
            <name>Public Repositories</name>
            <layout>default</layout>
            <url>my.repository</url>
        </repository>
</repositories>

标签: mavenmaven-plugin

解决方案


推荐阅读