plugins {
    id 'java'
    id 'maven-publish'
}

group 'com.microsoft.signalr'

java {
    withJavadocJar()
    withSourcesJar()
}

dependencies {
    implementation 'com.google.code.gson:gson:2.8.9'
    implementation 'com.squareup.okhttp3:okhttp:4.12.0'
    api 'io.reactivex.rxjava3:rxjava:3.0.11'
    implementation 'org.slf4j:slf4j-api:1.7.25'
}

base {
    archivesName = 'signalr'
}

publishing {
    publications {
        release(MavenPublication) {
            from components.java

            artifactId 'signalr'

            pom {
                packaging = 'jar'
                inceptionYear = '2018'
                url = 'https://github.com/dotnet/aspnetcore'
                name = groupId + ':' + artifactId
                description = 'ASP.NET Core SignalR Client for Java applications'
                licenses {
                    license {
                        name = 'MIT License'
                        url = 'https://opensource.org/licenses/MIT'
                        distribution = 'repo'
                    }
                }
                scm {
                    connection = 'scm:git:https://github.com/dotnet/aspnetcore.git'
                    developerConnection = 'scm:git:https://github.com/dotnet/aspnetcore.git'
                    url = 'https://github.com/dotnet/aspnetcore/tree/main'
                }
                developers {
                    developer {
                        id = 'microsoft'
                        name = 'Microsoft'
                    }
                }
            }
        }
    }
}

tasks.withType(GenerateMavenPom).all {
    destination = layout.buildDirectory.file("libs/signalr-${project.version}.pom").get().asFile
}

task generateVersionClass {
    inputs.property "version", project.version
    outputs.dir "$buildDir/generated"
    doFirst {
        def versionFile = file("$buildDir/../src/main/java/com/microsoft/signalr/Version.java")
        versionFile.parentFile.mkdirs()
        versionFile.text =
                """
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

package com.microsoft.signalr;

class Version {
    public static String getDetailedVersion() {
        return "$project.version";
    }
}
"""
    }
}

compileJava.dependsOn generateVersionClass
