apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'org.flywaydb.flyway'
apply plugin: 'java'

apply plugin: "pmd"

repositories {
    jcenter(){
        url "http://jcenter.bintray.com/"
    }
    flatDir {
        dirs 'lib'
    }
}

flyway {
    url = 'jdbc:mysql://localhost:3306'
    user = 'root'
    password = 'password'
    schemas = ['bookmarks']
    locations = ['classpath:db.migration']
}

pmd {
    ignoreFailures = true
    sourceSets = [sourceSets.main]
    reportsDir = file("$project.buildDir/reports/pmd")
    ruleSets = [
        "java-basic",
        "java-braces",
        "java-strings",
        "java-design",
        "java-unusedcode"
    ]
}

task stage {
    dependsOn build
}

// add CPD to check
check << {
  File outDir = new File("$project.buildDir/reports/pmd/")
  outDir.mkdirs()
  ant.taskdef(name: 'cpd', classname: 'net.sourceforge.pmd.cpd.CPDTask',
    classpath: configurations.pmd.asPath)
  ant.cpd(minimumTokenCount: '100', format: 'xml',
    outputFile: new File(outDir , 'cpd.xml')) {
    fileset(dir: "src/main/java") {
      include(name: '**/*.java')
    }
  }
}

buildscript {
    repositories {
        jcenter()
        flatDir {
            dirs 'lib'
        }
    }
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE'
        classpath 'org.flywaydb:flyway-gradle-plugin:3.2.1'
    }
}

jar {
    baseName = project.name
    version = '0.1.0'
    exclude('application.properties')
    exclude('gradle.properties')
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-starter-aop'
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile "org.springframework.boot:spring-boot-starter-actuator"

    compile("org.apache.commons:commons-lang3:3.2.1")
    compile("com.google.guava:guava:16.0.1")
    compile("org.yaml:snakeyaml:1.13")
    compile("mysql:mysql-connector-java:5.1.28")
    compile("org.postgresql:postgresql:9.4-1201-jdbc4")

    testCompile("junit:junit:4.11")
    testCompile 'org.hamcrest:hamcrest-all:1.3'
    testCompile "org.mockito:mockito-all:1.8.4"
    testCompile 'com.jayway.jsonpath:json-path:0.9.1'
    testCompile 'com.jayway.jsonpath:json-path-assert:0.9.1'
    testCompile("org.springframework:spring-test:4.0.6.RELEASE")
    testCompile("org.hsqldb:hsqldb:2.0.0")
    testCompile("org.skyscreamer:jsonassert:0.9.0")
}
