group = "dev.plex"
version = "1.0.1-SNAPSHOT"

allprojects {
    apply plugin: 'java'
    apply plugin: "maven-publish"
    repositories {
        maven {
            url = uri("https://papermc.io/repo/repository/maven-public/")
        }

        maven {
            url = uri("https://repository.apache.org/content/repositories/snapshots/")
        }

        maven {
            url = uri("https://repo.maven.apache.org/maven2/")
        }

        mavenCentral()
    }

    java {
        toolchain.languageVersion.set(JavaLanguageVersion.of(17))
    }

    tasks.withType(JavaCompile) {
        options.encoding = "UTF-8"
    }

    publishing {
        publications {
            maven(MavenPublication) {
                from(components.java)
            }
        }
        repositories {
            maven {
                def releasesRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-releases/")
                def snapshotsRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-snapshots/")
                url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
                credentials {
                    username = System.getenv("plexUser")
                    password = System.getenv("plexPassword")
                }
            }
        }
    }
}

task copyJars(type: Copy, dependsOn: subprojects.jar) {
    from(subprojects.jar)
    into project.file('jars')
}