Android kotlin Failed to upload the mavne configured for all submodules in the root directory configuration, name ‘release’ not found

child module build.gradle.kts


group = "net.xxxx.xxxx"
version = "1.0.0"
plugins {
    alias(libs.plugins.android.library) //  com.android.library 8.7.3
    alias(libs.plugins.kotlin.android) // org.jetbrains.kotlin.android 2.1.0
}

android {
    namespace = "net.xxxx.xxxx"
    compileSdk = 34
    defaultConfig {
        minSdk = 21

        testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
        consumerProguardFiles("consumer-rules.pro")
    }

    buildTypes {

        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
        debug {
            isMinifyEnabled = false
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
}
//afterEvaluate {
//    publishing {
//        publications {
//            create<MavenPublication>("release") {
//                println(components.asMap.keys)
//                from(components["release"])
//            }
//        }
//    }
//}
dependencies {
    implementation(libs.appcompat.v7)
    implementation(libs.retrofit)
    implementation(libs.okhttp3.loging.interceptor)
    implementation(libs.okhttp3.converter.gson)
    implementation(libs.woaoo.model)
    testImplementation(libs.junit)
    androidTestImplementation(libs.runner)
    androidTestImplementation(libs.espresso.core)
}

in the submodule project create(“release”) components can get[debug,release]

root build.gradle.kts

import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import io.gitlab.arturbosch.detekt.Detekt

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.kotlin.android) apply false
    alias(libs.plugins.jetbrains.kotlin.jvm) apply false
    alias(libs.plugins.arturbosch.detekt)
    alias(libs.plugins.android.library) apply false
    id("maven-publish")
}

subprojects {
    apply(plugin = "io.gitlab.arturbosch.detekt")
    apply(plugin = "maven-publish")

    detekt {
        source.from(files("src/main/java", "src/main/kotlin"))
        buildUponDefaultConfig = true
        allRules = false
        disableDefaultRuleSets = false
        debug = false
        parallel = false
    }

    tasks.withType<Detekt>().configureEach {
        reports {
            html.required.set(true)
            xml.required.set(true)
            txt.required.set(true)
            sarif.required.set(true)
        }
    }
    afterEvaluate {
        if (plugins.hasPlugin("com.android.library")) {
            publishing {
                publications {
                    println(components.asMap.keys)
                    create<MavenPublication>("${project.name}Release") {
                        artifactId = project.name 
                        if (artifactId == "app") return@create
                        val isJavaLib = components.asMap.keys.contains("kotlin")
                        if (isJavaLib) {
                            from(project.components.getByName("kotlin"))
                        } else {
                        from(components["release"]) 
                        }
                        groupId = project.group.toString() // 使用项目组作为 groupId
                        version = project.version.toString() // 使用项目版本作为 version
                    }
                }
//            repositories {
//                maven {
//                    isAllowInsecureProtocol = true
//                    name = "release"
//                    url = uri("http://xxxxxxx/repository/maven-releases")
//                    credentials {
//                        username = "xxxxx"
//                        password = "xxxxxxxx"
//                    }
//                }
            }
        }

    }
}
}

sync project will get a error and components is [] empty

* What went wrong:
A problem occurred configuring project ':xxxxx'.
> SoftwareComponent with name 'release' not found.

What I want to achieve is a unified configuration of maven packaging in the root directory, there are two sub-modules Java libray and Android library, and now the Java library is normal

0

I have solved in this way.
method invoke sequence is subprojects.afterEvaluate -> child.afterEvaluate. the components is create at child.afterEvaluate,so we can not get ‘release’ in subprojects.afterEvaluate,use gradle.projectsEvaluated is invoke after child.afterEvaluate

import io.gitlab.arturbosch.detekt.Detekt

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.kotlin.android) apply false
    alias(libs.plugins.jetbrains.kotlin.jvm) apply false
    alias(libs.plugins.arturbosch.detekt)
    alias(libs.plugins.android.library) apply false
    id("maven-publish")
}
gradle.projectsEvaluated {
    subprojects {
        detekt {
            source.from(files("src/main/java", "src/main/kotlin"))
            buildUponDefaultConfig = true
            allRules = false
            disableDefaultRuleSets = false
            debug = false
            parallel = false
        }

        tasks.withType<Detekt>().configureEach {
            reports {
                html.required.set(true)
                xml.required.set(true)
                txt.required.set(true)
                sarif.required.set(true)
            }
        }
        publishing {
            publications {
                create<MavenPublication>("${project.name}Release") {
                    if (artifactId == "app") return@create
                    val isJavaLib = components.asMap.keys.contains("kotlin")
                    if (isJavaLib) {
                        from(components.getByName("kotlin"))
                    } else {
                        from(components.getByName("release"))
                    }
                    groupId = project.group.toString() 
                    version = project.version.toString() 
                }
                create<MavenPublication>("${project.name}snapshot") {
                    artifactId = project.name 
                    if (artifactId == "app") return@create
                    val isJavaLib = components.asMap.keys.contains("kotlin")
                    if (isJavaLib) {
                        from(components.getByName("kotlin"))
                    } else {
                        from(components.getByName("release"))
                    }
                    groupId = project.group.toString() 
                    version = "${project.version}-SNAPSHOT"
                }
            }
            repositories {
                maven {
                    isAllowInsecureProtocol = true
                    name = "release"
                    url = uri("xxxxxxx")
                    credentials {
                        username = "xxxxx"
                        password = "xxxxxxxxxx"
                    }
                }
                maven {
                    isAllowInsecureProtocol = true=
                    name = "snapshot"
                    url = uri("http://xxxxxxxxx")
                    credentials {
                        username = "xxxxxx"
                        password = "xxxxxxxxx"
                    }
                }
            }
        }
    }
}

subprojects {
    apply(plugin = "io.gitlab.arturbosch.detekt")
    apply(plugin = "maven-publish")
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật