gpt4 book ai didi

android - Maven在Gradle插件中发布逻辑

转载 作者:行者123 更新时间:2023-12-03 05:33:52 24 4
gpt4 key购买 nike

我有一些库要发布到本地Maven。我想为此使用一个插件以最大程度地重用。

基本代码设置如下:

apply plugin: 'com.android.library'
apply plugin: 'LibraryPlugin'

android {
defaultConfig {
versionCode 1
versionName "1.0q"
}
}

def groupId = "x.y.z"
def artifactId = "LibZ"

project.afterEvaluate {
publishing {
publications {
parseDebugLibraryResources(MavenPublication) {
setGroupId groupId
setArtifactId artifactId
version = android.defaultConfig.versionName
}
}
}
}

./gradlew publishToMavenLocal之后,将其正确放置在此处。
我想将那个project.afterEvaluate> Publishing> Publications的东西移到Plugin中,这样我就可以在多个项目中重用它。

这是插件代码:
class LibraryPlugin : Plugin<Project> {

override fun apply(project: Project) {
project.plugins.apply("kotlin-android")
project.plugins.apply("maven-publish")
project.dependencies.add("implementation", BuildPlugins.kotlinStandardLibrary)
val extension = project.extensions.getByType<LibraryExtension>()
extension.configureLibrary()

project.afterEvaluate {
// publishing {

// }
}
}

private fun LibraryExtension.configureLibrary() {
setCompileSdkVersion(AndroidSdk.compile)
defaultConfig.apply {
setMinSdkVersion(AndroidSdk.min)
setTargetSdkVersion(AndroidSdk.target)
testInstrumentationRunner = TestLibraries.UI.instrumentationRunner
}
}
}

现在,它不知道Project.afterEvaluate中的“发布”节点。如何将该代码移入插件?

最佳答案

我需要这样的发布节点:

val publishing = project.properties["publishing"] as PublishingExtension

完整示例:
class LibraryPlugin : Plugin<Project> {

override fun apply(project: Project) {
project.plugins.apply("kotlin-android")
project.plugins.apply("maven-publish")
project.dependencies.add("implementation", BuildPlugins.kotlinStandardLibrary)
val extension = project.extensions.getByType<LibraryExtension>()
extension.configureLibrary()


project.afterEvaluate {
val publishing = project.properties["publishing"] as PublishingExtension
publishing {

}
}
}

private fun LibraryExtension.configureLibrary() {
setCompileSdkVersion(AndroidSdk.compile)
defaultConfig.apply {
setMinSdkVersion(AndroidSdk.min)
setTargetSdkVersion(AndroidSdk.target)
testInstrumentationRunner = TestLibraries.UI.instrumentationRunner
}
}
}

关于android - Maven在Gradle插件中发布逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57710776/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com