代码之家  ›  专栏  ›  技术社区  ›  matthewh86

com.jfrog.artifactory gradle plugin 401未经授权

  •  0
  • matthewh86  · 技术社区  · 6 年前

    我之前已经成功地设置了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 ,但没有成功(现在似乎也与 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 回复  |  直到 6 年前
        1
  •  0
  •   matthewh86    6 年前

    结果这是一个简单的解决办法。从Circleci的个人帐户转到使用组织时,环境变量丢失。