buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
    }
}

plugins {
    id 'org.jetbrains.kotlin.multiplatform' version '1.3.61'
    id("maven-publish")
}

apply plugin: 'com.bmuschko.nexus'

group 'dev.ktobe'
version '0.0.1'

repositories {
    mavenCentral()
}

kotlin {
    /* Targets configuration omitted. 
    *  To find out how to configure the targets, please follow the link:
    *  https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#setting-up-targets */
    jvm("jvm8") {
        mavenPublication { // Setup the publication for the target 'jvm6'
            // The default artifactId was 'foo-jvm6', change it:
            artifactId = "ktobe"
        }
    }

    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
    }

    // Default source set for JVM-specific sources and dependencies.
    // Alternatively, jvmMain { ... } would work as well:
    jvm("jvm8").compilations.main.defaultSourceSet {
        dependencies {
            implementation kotlin('stdlib-jdk8')
        }
    }
    // JVM-specific tests and their dependencies:
    jvm("jvm8").compilations.test.defaultSourceSet {
        dependencies {
            implementation kotlin('test-junit')
        }
    }
}

nexus {
    sign = true
    repositoryUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
    snapshotRepositoryUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
}

task sourceJar(type: Jar) {
    file "build/libs/ktobe-jvm8-${version}-sources.jar"
    classifier "sources"
}

publishing {
    publications {
        mavenJar(MavenPublication) {
            artifact "build/libs/ktobe-jvm8-${version}.jar"
            artifact "build/libs/ktobe-jvm8-${version}.jar.asc"
            artifact sourceJar
            pom {
                name = 'ktobe'
                description = 'Kotlin assertion library'
                url = 'https://github.com/augur/ktobe'
                inceptionYear = '2020'

                licenses {
                    license {
                        name = 'The Apache Software License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution = 'repo'
                    }
                }
                developers {
                    developer {
                        id = 'augur'
                        name = 'Denis Kilchichakov'
                        email = 'denis@kilchichakov.com'
                    }
                }
                scm {
                    url = 'https://github.com/augur/ktobe'
                    connection = 'https://github.com/augur/ktobe.git'
                    developerConnection = 'scm:git://github.com/augur/ktobe.git'
                }
            }
            repositories {
                maven {
                    name 'nexus'

                    def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
                    def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
                    url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
                    credentials {
                        username project.nexusUsername
                        password project.nexusPassword
                    }
                }
            }
        }
    }
}

signing {
    sign publishing.publications.mavenJar
}