Search code examples
javamavenbintrayjcenter

JCenter - Return code is: 401, ReasonPhrase: Unauthorized


When deploying with $mvn deploy for a linked artifact into JCenter, I get this error Return code is: 401, ReasonPhrase: Unauthorized.

What is causing this, and how to fix this?


Solution

  • Solution is to have this in the artifact's pom.xml

    <distributionManagement>
        <snapshotRepository>
            <id>bintray-yourusername-maven-yourpackagename</id> <!-- same id with the server in settings.xml -->
            <name>oss-jfrog-artifactory-snapshots</name>
            <url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url>
        </snapshotRepository>
    </distributionManagement>
    

    And have this in the settings.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
              xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
       <servers>
            <server>
                <id>bintray-yourusername-maven-yourpackagename</id> <!-- same id with the snapshotRepository -->
                <username>yourusername</username>
                <password>your_api_key</password>
            </server>
        </servers>
        <profiles>
            <profile>
                <repositories>
                    <repository>
                        <snapshots>
                            <enabled>false</enabled>
                        </snapshots>
                        <id>central</id>
                        <name>bintray</name>
                        <url>http://jcenter.bintray.com</url>
                    </repository>
                </repositories>
                <pluginRepositories>
                    <pluginRepository>
                        <snapshots>
                            <enabled>false</enabled>
                        </snapshots>
                        <id>central</id>
                        <name>bintray-plugins</name>
                        <url>http://jcenter.bintray.com</url>
                    </pluginRepository>
                </pluginRepositories>
                <id>bintray</id>
            </profile>
        </profiles>
        <activeProfiles>
            <activeProfile>bintray</activeProfile>
        </activeProfiles>
    </settings>