plugins {
    id 'java'
    id 'maven-publish'  // [Maven] Publish - https://docs.gradle.org/current/userguide/publishing_maven.html
}

group = 'fr.doap.dicofr'
version = '1.0-SNAPSHOT'

repositories {
    maven { url='https://maven.doap.fr/repository/maven-all/' }
}

dependencies {
    testImplementation platform('org.junit:junit-bom:5.10.0')
    testImplementation 'org.junit.jupiter:junit-jupiter'
}

test {
    useJUnitPlatform()
}

// [Maven Publish] - https://docs.gradle.org/current/userguide/publishing_maven.html
publishing {
    publications {
        maven(MavenPublication) {
            from components.java
        }
    }
    repositories {
        maven {
            if ((System.getenv('MAVEN_USERNAME') == null) || (System.getenv('MAVEN_PASSWORD') == null)) {
                throw new GradleException("You must define the Windows Environment variables MAVEN_USERNAME and MAVEN_PASSWORD to publish to the repository")
            }

            def releasesRepoUrl = "https://maven.doap.fr/repository/maven-releases/"
            def snapshotsRepoUrl = "https://maven.doap.fr/repository/maven-snapshots/"
            url = version.endsWith('-SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl

            credentials {
                username System.getenv('MAVEN_USERNAME')
                password System.getenv('MAVEN_PASSWORD')
            }
        }
    }
}