apply plugin: 'maven-publish'
apply plugin: 'signing'

group = ossrhGroupId
version = getReleaseVersion()

afterEvaluate {
    publishing {
        publications {
            android.libraryVariants.all { variant ->
                String flavorArtifactId = PUBLISH_ARTIFACT_ID
                String flavorName = variant.getFlavorName()
                if (flavorName != null && !flavorName.isEmpty()) {
                    flavorArtifactId = "$flavorArtifactId-$flavorName"
                }

                String descriptionLabel = "Godot OpenXR Vendors"
                String buildType = variant.buildType.name
                if (buildType == "debug") {
                    flavorArtifactId = "$flavorArtifactId-debug"
                    descriptionLabel = "$descriptionLabel (Debug)"
                }

                String variantName = variant.name

                "$variantName"(MavenPublication) {
                    from components."$variantName"

                    // The coordinates of the library, being set from variables that we'll set up later
                    groupId ossrhGroupId
                    artifactId flavorArtifactId
                    version getReleaseVersion()

                    // Mostly self-explanatory metadata
                    pom {
                        name = flavorArtifactId
                        description = descriptionLabel
                        url = 'https://github.com/GodotVR/godot_openxr_vendors#readme'
                        licenses {
                            license {
                                name = 'MIT License'
                                url = 'https://github.com/GodotVR/godot_openxr_vendors/blob/master/LICENSE'
                            }
                        }
                        developers {
                            developer {
                                id = 'm4gr3d'
                                name = 'Fredia Huya-Kouadio'
                                email = 'fhuyakou@gmail.com'
                            }
                            developer {
                                id = 'BastiaanOlij'
                                name = 'Bastiaan Olij'
                                email = 'mux213@gmail.com'
                            }
                            developer {
                                id = 'kisg'
                                name = 'Gergely Kis'
                            }
                            developer {
                                id = 'rsjtdrjgfuzkfg'
                                name = 'Dirk Steinmetz'
                            }
                            // Add all other devs here...
                        }

                        // Version control info - if you're using GitHub, follow the format as seen here
                        scm {
                            connection = 'scm:git:github.com/GodotVR/godot_openxr_vendors.git'
                            developerConnection = 'scm:git:ssh://github.com/GodotVR/godot_openxr_vendors.git'
                            url = 'https://github.com/GodotVR/godot_openxr_vendors/tree/master'
                        }
                    }
                }
            }
        }
    }
}

signing {
    useInMemoryPgpKeys(
        rootProject.ext["signing.keyId"],
        rootProject.ext["signing.key"],
        rootProject.ext["signing.password"],
    )
    sign publishing.publications
}
