简体   繁体   中英

Maven accessing private repository on bitbucket

I'm setting up maven repository for our project that is bitbucket private repository (following this blog ).

The problem is that maven 3.1.1 can not access private repository using basic auth. It downloads .pom as html with login request.

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:

<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. It also returns 401 response when using curl without login/password so bitbucket side seems to work as expected.

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 )

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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