Форум для тех, кто программирует под Android
Anonymous
Android kotlin Не удалось загрузить mavne, настроенный для всех подмодулей в конфигурации корневого каталога, имя «выпус
Сообщение
Anonymous » 13 дек 2024, 06:36
дочерний модуль 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("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)
}
в проекте подмодуля компоненты create("release") могут получить[debug,release]
корневую сборку. 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().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("${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"
// }
// }
}
}
}
}
}
Проект синхронизации выдаст ошибку, а компоненты [] пусты
Код: Выделить всё
* What went wrong:
A problem occurred configuring project ':xxxxx'.
> SoftwareComponent with name 'release' not found.
Я хочу добиться унифицированной конфигурации упаковки maven в корневом каталоге, есть два подмодуля Java libray и библиотека Android, и теперь библиотека Java работает нормально
Подробнее здесь:
https://stackoverflow.com/questions/792 ... s-in-the-r
1734060975
Anonymous
дочерний модуль build.gradle.kts [code] 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("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) } [/code] [b]в проекте подмодуля компоненты create("release") могут получить[debug,release][/b] корневую сборку. gradle.kts [code]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().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("${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" // } // } } } } } } [/code] Проект синхронизации выдаст ошибку, а компоненты [] пусты [code]* What went wrong: A problem occurred configuring project ':xxxxx'. > SoftwareComponent with name 'release' not found. [/code] Я хочу добиться унифицированной конфигурации упаковки maven в корневом каталоге, есть два подмодуля Java libray и библиотека Android, и теперь библиотека Java работает нормально Подробнее здесь: [url]https://stackoverflow.com/questions/79277160/android-kotlin-failed-to-upload-the-mavne-configured-for-all-submodules-in-the-r[/url]