Maven的使用发布插件,Android项目在摇篮5

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

我想建立一个脚本来发布使用“Maven的发布”插件APK文物的Nexus。在摇篮4有可能有这样的配置(这工作):

apply plugin: 'maven-publish'

publishing {
    repositories {
        maven {
            url "https://$MY_NEXUS_SERVER$/repository/${project.version.endsWith('-SNAPSHOT') ? 'snapshots' : 'releases'}"
            credentials {
                username mavenUser
                password mavenPassword
            }
        }
        publications {
            android.applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    if (variant.name == "release") {
                        create("apk${variant.name.capitalize()}", MavenPublication) {
                            groupId project.group
                            artifactId project.name
                            version project.version

                            artifact(output.outputFile)
                        }
                    }
                }
            }
        }
    }
}

在摇篮5 this is no longer possible

当试图建立项目中,我得到这个错误:

Cannot create a Publication named 'android' because this container does not support creating elements by name alone. Please specify which subtype of Publication to create. Known subtypes are: MavenPublication

我怎么可以重写这段代码是用摇篮5兼容?

android gradle android-gradle
1个回答
0
投票

我发现一些作品(等同于我的代码上面的例子):

apply plugin: 'maven-publish'

publishing {
    repositories {
        maven {
            url "https://$MY_NEXUS_SERVER$/repository/${project.version.endsWith('-SNAPSHOT') ? 'snapshots' : 'releases'}"
            credentials {
                username mavenUser
                password mavenPassword
            }
        }
        publications {
            create("apkRELEASE", MavenPublication) {
                afterEvaluate {
                    android.applicationVariants.all { variant ->
                        variant.outputs.each { output ->
                            if (variant.name == "release") {
                                groupId project.group
                                artifactId project.name
                                version project.version

                                artifact(output.outputFile)
                            }
                        }
                    }
                }
            }
        }
    }
}

0
投票

用于构建任意变体的另一选项(在摇篮5.5.1 / Android的摇篮3.5.0测试):

apply plugin: 'maven-publish'

publishing {
    repositories {
        maven {
            url "https://$MY_NEXUS_SERVER$/repository/${project.version.endsWith('-SNAPSHOT') ? 'snapshots' : 'releases'}"
            credentials {
                username mavenUser
                password mavenPassword
            }
        }
        publications {
            android.applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    "maven${variant.name.capitalize()}Apk"(MavenPublication) {
                        groupId project.group
                        artifactId project.name
                        version project.version

                        artifact(output.outputFile)
                    }
                }
            }
        }
    }
}

导致与调试版本建立在发布任务的例子:publishMavenDebugApkPublicationToMavenRepository

© www.soinside.com 2019 - 2024. All rights reserved.