简体   繁体   English

Maven访问bitbucket上的私有存储库

[英]Maven accessing private repository on bitbucket

I'm setting up maven repository for our project that is bitbucket private repository (following this blog ). 我正在为我们的项目设置maven存储库,这是bitbucket私有存储库(在此博客之后 )。

The problem is that maven 3.1.1 can not access private repository using basic auth. 问题是maven 3.1.1无法使用基本身份验证访问私有存储库。 It downloads .pom as html with login request. 它使用登录请求将.pom下载为html。

repository definition: 存储库定义:

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

Authentication from .m2/settings.xml: 来自.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>

Accessing resource using curl and basic auth works just fine. 使用curl和basic auth访问资源工作得很好。 It also returns 401 response when using curl without login/password so bitbucket side seems to work as expected. 当使用curl而没有登录/密码时,它也返回401响应,因此bitbucket端似乎按预期工作。

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

I suspect it has something to do with realm returned. 我怀疑它与返回的领域有关。

After trying many options, the only approach that works is preparing and sending Basic Auth header manually (from this link ) 尝试了很多选项后,唯一有效的方法是手动准备和发送Basic Auth标头(从此链接

<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>

You need to define the repository differently 您需要以不同方式定义存储库

<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>

Have a look at http://synergian.github.io/wagon-git/bitbucket.html as well 看看http://synergian.github.io/wagon-git/bitbucket.html

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

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