plugins {
  id 'java'
  id 'eclipse'
  id 'idea'
  id 'maven'
  id 'jacoco'
  id 'maven-publish'
  id 'com.jfrog.bintray' version '1.8.1'
  id "org.sonarqube" version "2.6.2"
}

group = 'com.github.aesteve'
version = '2.1-SNAPSHOT'

repositories {
  mavenCentral()
  maven {
    url = 'https://oss.sonatype.org/content/repositories/snapshots/'
  }
}

dependencies {
  // vertx
  compile "io.vertx:vertx-core:${vertxVersion}"
  compile "io.vertx:vertx-web:${vertxVersion}"
  compile "io.vertx:vertx-auth-common:${vertxVersion}"
  compile "io.vertx:vertx-auth-shiro:${vertxVersion}"
  compile "io.vertx:vertx-auth-jwt:${vertxVersion}"
  compile "io.vertx:vertx-auth-jdbc:${vertxVersion}"
  compile "io.vertx:vertx-jdbc-client:${vertxVersion}"

  compile "io.vertx:vertx-service-proxy:${vertxVersion}"
  compile "io.vertx:vertx-codegen:${vertxVersion}"

  // template engines
  compile "io.vertx:vertx-web-templ-handlebars:${vertxVersion}"
  compile "io.vertx:vertx-web-templ-mvel:${vertxVersion}"
  compile "io.vertx:vertx-web-templ-jade:${vertxVersion}"
  compile "io.vertx:vertx-web-templ-thymeleaf:${vertxVersion}"

  // reflection
  compile 'io.github.lukehutch:fast-classpath-scanner:2.18.1'
  compile 'org.reflections:reflections:0.9.11'
  compile 'commons-beanutils:commons-beanutils:1.9.2'

  // tests
  testCompile 'com.github.jknack:handlebars:1.3.0'
  testCompile "io.vertx:vertx-unit:${vertxVersion}"
  testCompile 'junit:junit:4.12'
  testCompile 'ch.qos.logback:logback-classic:1.2.3'
}

compileTestJava {
  options.compilerArgs << '-parameters'
}

/* Service Proxy related */
def generatedSrcPath = "$buildDir/generated-src"
def generatedSrcDir = file(generatedSrcPath)

sourceSets {
  test {
    java.srcDirs += generatedSrcDir
    output.dir(builtBy: 'generateServiceProxy', generatedSrcPath)
  }
}

task generateServiceProxy(type: JavaCompile, description: 'Generates EBServiceProxies') {
  source = [sourceSets.test.java, sourceSets.main.java]
  classpath = configurations.testCompile
  destinationDir = generatedSrcDir
  options.compilerArgs = [
      "-proc:only",
      "-processor", "io.vertx.codegen.CodeGenProcessor",
      "-AoutputDirectory=$generatedSrcPath"
  ]
}


compileTestJava.dependsOn generateServiceProxy

clean {
  delete += generatedSrcDir
}

bintray {
  user = 'aesteve'
  key = System.getenv 'BINTRAY_KEY'
  pkg {
    repo = 'maven'
    name = project.name
    licenses = ['Apache-2.0']
    vcsUrl = 'https://github.com/aesteve/nubes'
    labels = ['vertx', 'vert.x', 'annotations', 'jax-rs', 'resteasy']
    publicDownloadNumbers = true
    version {
      name = project.version
      description = 'Nubes stratus nebulosus'
    }
    publications = ['maven']
  }
}

publishing {
  publications {
    maven(MavenPublication) {
      from components.java
      artifact sourcesJar
    }
  }
}

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

test.outputs.upToDateWhen { false }
test {
  finalizedBy jacocoTestReport
}
jacocoTestReport {
    reports {
        xml.enabled true
        html.enabled true
    }
}
tasks.sonarqube.dependsOn = []


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