apply plugin: 'java'
apply plugin: 'kotlin'
group 'io.cdep'

if (System.getenv()["TRAVIS_TAG"] != null && System.getenv()["TRAVIS_TAG"].length() > 0) {
    version System.getenv()["TRAVIS_TAG"]
} else {
    version 'dev'
}
repositories {
  jcenter()
}

buildscript {
    ext.kotlin_version = '1.2.30'
    repositories {
      jcenter()
  }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

class GenerateBuildInfo extends DefaultTask {
    @OutputFile
    public File buildInfoFile = new File("bootstrap/src/main/java/io/cdep/bootstrap/BuildInfo.java")

    @TaskAction
    generate() {
        buildInfoFile.parentFile.mkdirs()
        buildInfoFile.write(
                """package io.cdep.bootstrap;
class BuildInfo {
  static final String PROJECT_VERSION = "$project.version";
}""")
    }
}

task generateBuildInfo(type : GenerateBuildInfo)
compileJava.dependsOn generateBuildInfo
//compileJava.source generateBuildInfo.buildInfoFile


task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

dependencies {
    compile 'org.yaml:snakeyaml:1.17'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    testCompile group: 'com.google.guava', name: 'guava', version: '20.0'
    testCompile group: 'com.google.truth', name: 'truth', version: '0.31'
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}