plugins {
    id 'java-library'
    id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
    id 'com.diffplug.spotless' version '5.14.0'
}

group 'io.getstream.client'
version = '3.23.0'
description = 'Stream Feeds official Java SDK'

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://plugins.gradle.org/m2/" }
    maven { url uri('https://repo.maven.apache.org/maven2/') }
}

var jackson_version = '2.14.2'

dependencies {
    java {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
    
    testImplementation 'junit:junit:4.13.1'
    testImplementation 'com.pholser:junit-quickcheck-core:0.8.1'
    testImplementation 'com.pholser:junit-quickcheck-generators:0.8.1'
    testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.2.0'

    implementation 'com.google.guava:guava:31.1-jre'
    implementation 'com.squareup.okhttp3:okhttp:4.10.0'
    implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version"
    implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version"
    implementation "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
    implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
    implementation 'com.auth0:java-jwt:4.2.2'

    api 'net.sourceforge.streamsupport:streamsupport:1.7.0'
    api 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.0'
}

def localProperties = new Properties()
def localPropertiesFile = project.rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    FileInputStream stream = new FileInputStream(localPropertiesFile)
    localProperties.load(stream)
}

test {
    useJUnitPlatform()

    testLogging {
        exceptionFormat = 'full'
        events 'standard_out', 'standard_error', "passed", "skipped", "failed"
    }

    doFirst {
        // Inject local properties into tests runtime system properties
        for (String key : localProperties.stringPropertyNames) {
            systemProperty key, localProperties.getProperty(key).toString()
        }
    }
}

def generatedVersionDir = "${buildDir}/generated-version"

sourceSets {
    main {
        output.dir(generatedVersionDir, builtBy: 'generateVersionProperties')
    }
}
/*spotless {
    java {
        googleJavaFormat()
    }
}*/
task generateVersionProperties {
    doLast {
        def propertiesFile = file "$generatedVersionDir/version.properties"
        propertiesFile.parentFile.mkdirs()
        def properties = new Properties()
        properties.setProperty("version", rootProject.version.toString())
        propertiesFile.withWriter { properties.store(it, null) }
    }
}
processResources.dependsOn generateVersionProperties

apply from: "publish.gradle"
