【问题标题】:Maven accessing private repository on bitbucketMaven 访问 bitbucket 上的私有存储库
【发布时间】:2013-11-17 15:22:20
【问题描述】:

我正在为我们的项目设置 maven 存储库,即 bitbucket 私有存储库(在 this blog 之后)。

问题是 maven 3.1.1 无法使用基本身份验证访问私有存储库。它将 .pom 下载为带有登录请求的 html。

存储库定义:

    <repository>
        <id>project-maven-repo</id>
        <url>https://bitbucket.org/company/maven-repo/raw/master/repository/</url>
    </repository>

来自 .m2/settings.xml 的身份验证:

<settings>
    <localRepository/>
    <interactiveMode/>
    <usePluginRegistry/>
    <offline/>
    <pluginGroups/>
    <servers>
        <server>
            <id>project-maven-repo</id>
            <username>bitbucketuser</username>
            <password>password</password>
        </server>
    </servers>
        <proxies/>
    <activeProfiles/>
    <profiles/>
</settings>

使用 curl 和基本身份验证访问资源效果很好。当使用没有登录名/密码的 curl 时,它还会返回 401 响应,因此 bitbucket 端似乎可以按预期工作。

curl -v -u bitbucketuser:password https://bitbucket.org/company/maven-repo/raw/master/README

我怀疑这与返回的领域有关。

【问题讨论】:

  • settings.xml文件中id的命名要与pom文件(repository)中的id一致。否则 Maven 无法获取有关凭据的信息。
  • 更新了问题,这里不是问题。

标签: maven bitbucket


【解决方案1】:

在尝试了许多选项之后,唯一可行的方法是手动准备和发送 Basic Auth 标头(来自 this link

<settings>
    <servers>
        <server>
            <id>project-maven-repo</id>
            <configuration>
                <httpHeaders>
                    <property>
                        <name>Authorization</name>
                        <!-- Base64-encoded "bitbucketuser:password" -->
                        <value>Basic Yml0YnVja2V0dXNlcjpwYXNzd29yZA==</value>
                    </property>
                </httpHeaders>
            </configuration>
        </server>
    </servers>
</settings>

【讨论】:

  • 非常感谢您提供此信息,我没有注意到也可以为服务器配置标头。再次感谢您
【解决方案2】:

您需要以不同的方式定义存储库

<repository>
  <id>your-repo-id</id>
  <name>Your Repo Name</name>
  <releases>
    <enabled>true</enabled>
  </releases>
  <snapshots>
    <enabled>false</enabled>
  </snapshots>
  <url>https://api.bitbucket.org/1.0/repositories/yourbitbucketusername/your-bitbucket-repo/raw/your-branch</url>
</repository>

也看看http://synergian.github.io/wagon-git/bitbucket.html

【讨论】:

    猜你喜欢
    • 2018-03-19
    • 1970-01-01
    • 2013-08-10
    • 2022-09-13
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    • 2017-04-17
    • 2018-01-06
    相关资源
    最近更新 更多