bintray-release添加对Maven Central同步的支持(五)

本文介绍如何通过修改Gradle配置来实现与MavenCentral的同步,包括定义必要的扩展属性及生成符合MavenCentral标准的pom文件的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文章摘要:
1、添加对Maven Central同步配置


系列文章:
bintray-release使用指南(一)
bintray-release配置publish闭包(二)
bintray-release自定义Publication(三)
bintray-release定义额外产品(四)
bintray-release添加对Maven Central同步的支持(五)

作为依赖关系最受欢迎的存储库,jCenter已经超越了Maven Central,该插件不能全面支持bintray和Maven Central之间的开箱即用(您可以阅读完整的讨论)。

尽管在生成的pom文件中添加缺少的字段是很容易的。

除了上述步骤之外,请执行以下操作:
- 打开你的项目的“build.gradle”。
- 定义一些这样的扩展属性,并用您自己的值替换占位符。 它们将被用于生成不会被Maven Central拒绝的pom文件的钩子。 如果您调用./gradlew bintrayUploadIS_UPLOADING将为true。

ext {
    ARTIFACT_ID = 'YOUR_ARTIFACT_ID'
    VERSION_NAME = 'YOUR_VERSION_NAME'
    VERSION_CODE = 1 //your version

    DESCRIPTION = 'YOUR_DESCRIPTION'

    SITE_URL = 'YOUR_SITE_URL'
    GIT_URL = 'YOUR_GIT_URL'
    GROUP_NAME = 'YOUR_GROUP_NAME'
    COMPILE_SDK = 23
    BUILD_TOOLS = '23.0.1'

    MODULE_NAME = 'YOUR_MODULE_NAME'

    LICENSE = 'YOUR_LICENSE'

    DEVELOPER_ID = 'YOUR_DEVELOPER_ID'
    DEVELOPER_NAME = 'YOUR_NAME'
    DEVELOPER_EMAIL = 'YOUR_EMAIL_ADDRESS'

    IS_UPLOADING = project.getGradle().startParameter.taskNames.any{it.contains('bintrayUpload')}
}

随意在其他地方定义这些属性。 他们往往具有应用普遍的性质,你可能已经有一个你定义属性的地方。

  • 添加钩子首先将会删除pom文件并重新生成符合Maven Central标准的文件。 如果要将hock应用于项目中的多个模块,请确保在if-clause中指定所有模块。
subprojects {
    group = GROUP_NAME
    version = VERSION

    if (IS_UPLOADING && project.name in [MODULE_NAME]) {
        println project.name
        apply plugin: 'maven'

        gradle.taskGraph.whenReady { taskGraph ->
            taskGraph.getAllTasks().find {
                it.path == ":$project.name:generatePomFileForMavenPublication"
            }.doLast {
                file("build/publications/maven/pom-default.xml").delete()
                println 'Overriding pom-file to make sure we can sync to maven central!'
                pom {
                    //noinspection GroovyAssignabilityCheck
                    project {
                        name "$project.name"
                        artifactId ARTIFACT_ID
                        packaging project.name == 'compiler' ? 'jar' : 'aar'
                        description DESCRIPTION
                        url SITE_URL
                        version VERSION_NAME

                        scm {
                            url GIT_URL
                            connection GIT_URL
                            developerConnection GIT_URL
                        }

                        licenses {
                            license {
                                name LICENSE
                            }
                        }

                        developers {
                            developer {
                                id DEVELOPER_ID
                                name DEVELOPER_NAME
                                email DEVELOPER_EMAIL
                            }
                        }
                    }
                }.writeTo("build/publications/maven/pom-default.xml")
            }
        }
    }
}
项目的build.gradle.kts文件如下: buildscript { repositories { google() mavenCentral() maven { url = uri("https://maven.aliyun.com/repository/public") } maven { url = uri("https://dl.bintray.com/openinstall/maven")} } dependencies { classpath("com.android.tools.build:gradle:8.10.1") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22") } } repositories { google() } APP的build.gradle.kts文件如下: plugins { id("com.android.application") id("org.jetbrains.kotlin.android") } android { namespace = "com.example.gyppcx" // Kotlin DSL 使用等号赋值 compileSdk = 36 // 属性名是 compileSdk,不是 compileSdkVersion defaultConfig { applicationId = "com.example.gyppcx" // 使用等号赋值 minSdk = 26 // 属性名是 minSdk,不是 minSdkVersion //noinspection OldTargetApi,EditedTargetSdkVersion targetSdk = 34 // 属性名是 targetSdk,不是 targetSdkVersion versionCode = 1 versionName = "1.0" } signingConfigs { create("release") { storeFile = file("../gyppcx.jks") storePassword = "Liu=123456" keyAlias = "key0" keyPassword = "Liu=123456" } } buildTypes { release { signingConfig = signingConfigs.getByName("release") isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) } } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = "17" } buildFeatures { compose = true } composeOptions { kotlinCompilerExtensionVersion = "1.5.10" } } // 添加依赖项(如果有) repositories { google() mavenCentral() maven { url = uri("https://maven.aliyun.com/repository/public") } maven { url = uri("https://dl.bintray.com/openinstall/maven")} } dependencies { implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) implementation("androidx.appcompat:appcompat:1.7.0") // 确保版本号与项目兼容 implementation("androidx.core:core-ktx:1.13.1") implementation("androidx.webkit:webkit:1.10.0") implementation("com.google.android.material:material:1.11.0") testImplementation("org.junit.jupiter:junit-jupiter:5.10.1") implementation("androidx.compose.ui:ui:1.7.0") implementation("androidx.compose.material3:material3:1.3.0") implementation("androidx.compose.ui:ui-tooling-preview:1.7.0") debugImplementation("androidx.compose.ui:ui-tooling:1.7.0") implementation("androidx.activity:activity-compose:1.8.2") } dependencies { //implementation(files("libs/OpenInstall_v2.8.5.jar")) // 添加这行 implementation("com.openinstall:openinstall-sdk:latest_version") implementation("androidx.appcompat:appcompat:1.7.0") // 确保版本号与项目兼容 implementation("androidx.core:core-ktx:1.13.1") implementation("androidx.webkit:webkit:1.10.0") implementation("com.google.android.material:material:1.11.0") testImplementation("org.junit.jupiter:junit-jupiter:5.10.1") implementation("androidx.compose.ui:ui:1.7.0") implementation("androidx.compose.material3:material3:1.3.0") implementation("androidx.compose.ui:ui-tooling-preview:1.7.0") debugImplementation("androidx.compose.ui:ui-tooling:1.7.0") implementation("androidx.activity:activity-compose:1.8.2") } repositories { maven { url = uri("https://maven.aliyun.com/repository/public") } } build sync时报错如下: Failed to resolve: com.openinstall:openinstall-sdk:latest_version build output时报错如下: FAILURE: Build completed with 10 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeReleaseNativeLibs'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:checkReleaseDuplicateClasses'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== 3: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:checkReleaseAarMetadata'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== 4: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mapReleaseSourceSetPaths'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== 5: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeReleaseResources'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== 6: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:processReleaseMainManifest'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== 7: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:desugarReleaseFileDependencies'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== 8: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeReleaseArtProfile'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== 9: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeReleaseAssets'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== 10: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:collectReleaseDependencies'. > Could not resolve all files for configuration ':app:releaseRuntimeClasspath'. > Could not find com.openinstall:openinstall-sdk:latest_version. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://repo.maven.apache.org/maven2/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://maven.aliyun.com/repository/public/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom - https://dl.bintray.com/openinstall/maven/com/openinstall/openinstall-sdk/latest_version/openinstall-sdk-latest_version.pom Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. For more on this, please refer to https://docs.gradle.org/8.14.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. BUILD FAILED in 5s
最新发布
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hailushijie

您的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值