plugins {
  id "java"
  id "org.springframework.boot" version "2.2.5.RELEASE"
  id 'io.spring.dependency-management' version '1.0.9.RELEASE'
  //id "com.gorylenko.gradle-git-properties" version "2.2.2"
  id "com.diffplug.gradle.spotless" version "3.27.1"
  id "org.sonarqube" version "2.8"
  id "jacoco"
}

group = 'ch.bag.screening'

// Java & Spring

sourceCompatibility = 11
targetCompatibility = 11

springBoot {
  buildInfo()
}

// Dependencies

repositories {
  mavenLocal()
  mavenCentral()
}

dependencies {
  // Spring Boot
  implementation 'org.springframework.boot:spring-boot-starter-web'
  implementation 'org.springframework.boot:spring-boot-starter-security'
  annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'

  // MSSQL storage
  implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
  implementation 'com.microsoft.sqlserver:mssql-jdbc:8.2.1.jre11'
  implementation 'org.flywaydb:flyway-core'

  // Azure file storage
  implementation 'com.azure:azure-storage-file-share:12.2.0'

  // Monitoring
  implementation 'org.springframework.boot:spring-boot-starter-actuator'
  implementation 'org.springframework.boot:spring-boot-starter-logging'
  implementation 'io.micrometer:micrometer-core'

  // Utilities
  implementation 'com.auth0:java-jwt:3.9.0'
  implementation 'com.google.code.findbugs:jsr305:3.0.2'
  implementation 'org.apache.commons:commons-lang3:3.9'
  implementation 'org.apache.commons:commons-text:1.8'
  implementation 'org.apache.commons:commons-collections4:4.4'


  // Documentation
  implementation 'org.springdoc:springdoc-openapi-ui:1.2.24'

  // Lombok
  compileOnly 'org.projectlombok:lombok'
  annotationProcessor 'org.projectlombok:lombok'
  testCompileOnly 'org.projectlombok:lombok'
  testAnnotationProcessor 'org.projectlombok:lombok'

  // Testing
  testImplementation('org.springframework.boot:spring-boot-starter-test') {
    exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
  }
  testImplementation 'org.springframework.security:spring-security-test'
}

// Quality

test {
  useJUnitPlatform()
  jacoco {
    destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
    classDumpDir = file("$buildDir/jacoco/classpathdumps")
  }
}

sonarqube {
  properties {
    property "sonar.jacoco.reportPaths", "$buildDir/jacoco/jacocoTest.exec"
  }
}

spotless {
  // Apply Google Java Format
  java {
    googleJavaFormat()
  }
  // Apply similar format to other files
  format "misc", {
    target "**/.gitignore", "**/*.gradle", "**/*.md", "**/*.sh"
    indentWithSpaces()
    trimTrailingWhitespace()
    endWithNewline()
  }
}
