buildscript {
    ext.kotlin_version = '1.1.1'

    repositories {
        mavenCentral()
        maven {
            name 'JFrog OSS snapshot repo'
            url  'https://oss.jfrog.org/oss-snapshot-local/'
        }
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'kotlin'
apply plugin: 'java'
apply plugin : 'maven'
apply plugin: 'idea'

def kllvmVersion = "0.1.1-SNAPSHOT"

project.group   = "me.tomassetti"
project.version = kllvmVersion

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}

dependencies {
  compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
  testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
  testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
  testCompile 'junit:junit:4.12'
}

task version {
  doLast {
    print "Version ${kllvmVersion}"
  }
}

task javadocJar(type: Jar) {
  classifier = 'javadoc'
  from javadoc
}

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

if (JavaVersion.current().isJava8Compatible()) {
  allprojects {
    tasks.withType(Javadoc) {
      options.addStringOption('Xdoclint:none', '-quiet')
    }
  }
}

artifacts {
    archives javadocJar, sourcesJar
  }

task generatePom {
  doLast {
    def generatedPom = pom {
      project {
        name project.name
        description "Framework to support building languages with Kotlin"
        version kllvmVersion
        packaging 'jar'
        url 'https://github.com/ftomassetti/kllvm'

        scm {
          connection 'scm:git:https://github.com/javaparser/kllvm.git'
          developerConnection 'scm:git:git@github.com:javaparser/kllvm.git'
          url 'https://github.com/ftomassetti/kllvm.git'
        }

        licenses {
          license {
            name 'Apache Licenve V2.0'
            url 'https://www.apache.org/licenses/LICENSE-2.0'
            distribution 'repo'
          }
        }

        developers {
          developer {
            id = 'ftomassetti'
            name = 'Federico Tomassetti'
            email = 'federico@tomassetti.me'
          }
        }
      }
    }
    generatedPom.writeTo("$buildDir/pom.xml")
  }
}

task sign(type:Exec) {
  doLast {
    String home = System.getProperty("user.home")
    String passphrase = new File(home + '/.gnupg/passphrase.txt').text
    commandLine 'gpg2', '--passphrase', passphrase, '--batch', '--yes', '--no-tty', '-ab', 'build/pom.xml'
  }
}

test {
  testLogging {
    exceptionFormat = 'full'
  }
}

task wrapper(type: Wrapper) {
    gradleVersion = '3.3'
}
