com.jfrog.artifactory gradle插件401未经授权

时间:2018-06-29 17:45:37

标签: gradle artifactory bintray

我以前已经成功设置了二进制文件夹和工件帐户,以将快照版本发布到OSS JFrog Artifactory存储库,但是在同一用户下设置GitHub / Bintray / Artifactory组织之后,我无法发布快照。

尝试运行时

./gradlew artifactoryPublish -Dsnapshot=true -DbintrayUser=myBintrayUser -DbintrayKey=myBintrayApiKey -DbuildNumber=#

我收到以下错误:

java.io.IOException: Failed to deploy file. Status code: 401 Response message: Artifactory returned the following errors: 
Unauthorized Status code: 401

我曾经尝试使用两个托盘用户(我的个人和组织),但是得到的响应是相同的。我还尝试过在https://bintray.com/profile/edit处重新生成一个新的API密钥,但是没有用(现在似乎也与https://oss.jfrog.org/artifactory/webapp/#/profile处的密钥不同步),无法编辑。

build.gradle文件是:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
    }
}

plugins {
    id 'java-library'
    id 'maven'
    id 'maven-publish'

    // Automatic SEMVER
    // ./gradlew release
    id 'net.vivin.gradle-semantic-build-versioning' version '4.0.0' apply false

    // SNAPSHOT publishing to oss-jfrog-artifactory
    // ./gradlew artifactoryPublish -Dsnapshot=true -DbintrayUser=<YOUR_USER_NAME> -DbintrayKey=<YOUR_API_KEY> -DbuildNumber=NNN
    id 'com.jfrog.artifactory' version '4.6.2'

    // RELEASE publishing to bintray
    // ./gradlew bintrayUpload -DbintrayUser=<YOUR_USER_NAME> -DbintrayKey=<YOUR_API_KEY>
    id 'com.jfrog.bintray' version '1.8.1'
}

wrapper.gradleVersion = '4.5.1'

def groupName = 'noxtech'
group = 'uk.co.noxtech'
archivesBaseName = 'noxtech-java-utils'
description = 'Assorted Java 8 utilities'
def projectUrl = "https://github.com/noxtech/noxtech-java-utils"

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}

dependencies {
    api 'joda-time:joda-time:2.9.9'

    implementation 'org.projectlombok:lombok:1.16.20'

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.hamcrest:hamcrest-all:1.3'
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

javadoc.failOnError = false
task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

def pomConfig = {
    licenses {
        license {
            name "The Apache Software License, Version 2.0"
            url "http://www.apache.org/licenses/LICENSE-2.0.txt"
            distribution "repo"
        }
    }

    scm {
        url projectUrl
    }
}

publishing {
    publications {
        mavenPublication(MavenPublication) {
            from components.java
            artifact sourcesJar {
                classifier "sources"
            }
            artifact javadocJar {
                classifier "javadoc"
            }
            groupId = project.group
            artifactId = project.archivesBaseName
            version = project.version.toString()
            pom.withXml {
                def root = asNode()
                root.appendNode('description', project.description)
                root.appendNode('name', project.name)
                root.appendNode('url', projectUrl)
                root.children().last() + pomConfig
            }
       }
    }
    repositories {
        maven {
            // change to point to your repo, e.g. http://my.org/repo
            url "$buildDir/repo"
        }
    }
}

bintray {
    user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
    key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : System.getenv('BINTRAY_KEY')
    publications = ['mavenPublication']
    pkg {
        repo = "maven"
        name = project.archivesBaseName
        userOrg = groupName
        licenses = ['Apache-2.0']
        websiteUrl = projectUrl
        vcsUrl = projectUrl + '.git'
        issueTrackerUrl = projectUrl + '/issues'
        version {
            name = project.version.toString()
            desc = project.description
            vcsTag = project.version.toString()
            released = new Date()
        }
    }
}

artifactory {
    contextUrl = 'http://oss.jfrog.org'
    publish {
        repository {
            repoKey = 'oss-snapshot-local'
            username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
            password = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : System.getenv('BINTRAY_KEY')
        }
        defaults {
            publications('mavenPublication')
            publishArtifacts = true
            publishPom = true
        }
    }
    resolve {
        repoKey = 'jcenter'
    }
    clientConfig.info.setBuildNumber(project.hasProperty('buildNumber') ? project.property('buildNumber') : System.getenv('BUILD_NUMBER'))
}

1 个答案:

答案 0 :(得分:0)

事实证明这是一个简单的解决方案。从CircleCI上的个人帐户转移到使用组织时,环境变量丢失了。