Gradle 发布无法每次将不同的随机文件 PUT 到 s01.oss.sonatype.org/service/local/staging/deploy/maven2

问题描述 投票:0回答:1

我正在尝试将我的Android库发布到https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/,每次任务都会失败,因为它无法放置其中一个文件出现 401 未经授权的错误。

问题是,每次都是不同的文件。这是任务在超过 16 次尝试中失败的不同文件的列表:

caimito-2.0.1-sources.jar.asc
caimito-2.0.2.module.asc
caimito-2.0.2-sources.jar.asc.md5
caimito-2.0.2.module.asc.sha1
caimito-2.0.2.pom.asc
caimito-2.0.2.module.md5
caimito-2.0.2-sources.jar.sha1
caimito-2.0.2-sources.jar
caimito-2.0.2.aar.asc.md5

我已经成功发布了我的库,因为在某些时候被省略的文件是 MD5,sonatype 不需要我创建一个版本。但这显然不是一个理想的情况,我想弄清楚发生了什么。

这些是我的构建文件:

plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.android")
}

android {
    namespace = "dev.gravitycode.caimito"
    compileSdk = 34

    defaultConfig {
        minSdk = 26
        // targetSdk = 34
        testOptions.targetSdk = 34
        lint.targetSdk = 34

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

    publishing {
        singleVariant("release") {
            withSourcesJar()
            // withJavadocJar()
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    composeOptions {
        kotlinCompilerExtensionVersion = "1.5.10"
    }

    buildFeatures {
        buildConfig = true
        compose = true
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {

    // AndroidX
    implementation("androidx.core:core-ktx:1.12.0")
    implementation("androidx.appcompat:appcompat:1.6.1")

    // Material Design
    implementation("com.google.android.material:material:1.11.0")

    // Google Guava
    implementation("com.google.guava:guava:33.0.0-android")

    // Jetbrains Annotations
    implementation("org.jetbrains:annotations:24.1.0")

    // Data Store
    implementation("androidx.datastore:datastore-preferences:1.0.0")

    // Compose
    implementation("androidx.activity:activity-compose:1.8.2")
    implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
    implementation(platform("androidx.compose:compose-bom:2024.03.00"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    implementation("androidx.compose.material3:material3")
    debugImplementation("androidx.compose.ui:ui-tooling")

    testImplementation("junit:junit:4.13.2")

    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}

apply(from = "../publish-package.gradle")

发布包.gradle

apply plugin: 'maven-publish'
apply plugin: 'signing'

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                groupId = 'dev.gravitycode.caimito'
                artifactId = 'caimito'
                version = '2.0.2'

                // Specify the components to publish
                from components.release

                pom {
                    name = 'caimito'
                    description = 'A small library of helpful classes for working with Android'
                    url = 'https://github.com/abuicke/caimito'

                    licenses {
                        license {
                            name = 'MIT License'
                            url = 'https://opensource.org/licenses/MIT'
                        }
                    }

                    developers {
                        developer {
                            id = 'adambuicke'
                            name = 'Adam Buicke'
                            email = '[email protected]'
                        }
                    }

                    scm {
                        connection = 'scm:git:github.com/abuicke/caimito.git'
                        developerConnection = 'scm:git:ssh://github.com/abuicke/caimito.git'
                        url = 'https://github.com/abuicke/caimito'
                    }
                }
            }
        }

        // Repository configuration
        repositories {
            maven {
                url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")

                credentials {
                    username = project.findProperty("ossrhUsername")
                    password = project.findProperty("ossrhPassword")
                }
            }
        }
    }

    // Signing configuration (if required)
    signing {
        sign publishing.publications.release
    }
}

这可能是 Sonatype、Gradle 或我的配置的问题吗?

android android-gradle-plugin android-library maven-central maven-publish
1个回答
0
投票

联系 Sonatype 支持后,我发现解决方案是使用您的用户令牌作为用户名和密码:

    // Repository configuration
    repositories {
        maven {
            url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")

            credentials {
                /**
                 * Regular username and password fails with gradle. Requires user token to work.
                 *
                 * NOTE: The user token may change frequently, so always
                 * check the most up to date user token has been applied.
                 * */
                username = project.findProperty("ossrhUserTokenUsername")//project.findProperty("ossrhUsername")
                password = project.findProperty("ossrhUserTokenPassword")//project.findProperty("ossrhPassword")
            }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.