apply plugin: 'com.diffplug.spotless'

spotless {
  java {
    googleJavaFormat('1.9')
    licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|public|// Includes work from:)'
    target 'src/**/*.java'
  }
  groovy {
    licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|class)'
  }
  scala {
    scalafmt()
    licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|public)'
    target 'src/**/*.scala'
  }
  kotlin {
    // ktfmt() // only supports 4 space indentation
    ktlint().userData(['indent_size': '2', 'continuation_indent_size': '2'])
    licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|public)'
  }
  format 'misc', {
    // not using '**/...' to help keep spotless fast
    target '.gitignore', '*.md', 'src/**/*.md', '*.sh', 'src/**/*.properties'
    indentWithSpaces()
    trimTrailingWhitespace()
    endWithNewline()
  }
}

task formatCode(dependsOn: ['spotlessApply'])
check.dependsOn 'spotlessCheck'
