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

com.jfrog.artifactory gradle plugin 401 Unauthorised

我之前成功设置了bintray和artifactory账号发布快照版本到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

我试过同时使用 bintray 用户(我的个人用户和组织用户),但得到了相同的响应。我还尝试在 https://bintray.com/profile/edit, but has not worked (and now also seems to be out of sync with the key at https://oss.jfrog.org/artifactory/webapp/#/profile) 重新生成一个新的 API 键,我无法编辑它。

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'))
}

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