Skip to content
Snippets Groups Projects
build.gradle 3.87 KiB
Newer Older
  • Learn to ignore specific revisions
  • buildscript {
      repositories {
        jcenter()
      }
      dependencies {
        classpath "com.diffplug.spotless:spotless-plugin-gradle:3.27.1"
        classpath "com.github.spotbugs:spotbugs-gradle-plugin:3.0.0"
        classpath "gradle.plugin.com.star-zero.gradle:githook:1.2.0"
      }
    }
    
    
    plugins {
      id 'eclipse-wtp'
    
      id 'jacoco'
    
      id 'java-library'
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    apply from: "${projectDir}/gradle/git-hooks.gradle"
    apply from: "${projectDir}/gradle/spotbugs.gradle"
    apply from: "${projectDir}/gradle/spotless.gradle"
    
    sourceCompatibility = JavaVersion.VERSION_11
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    compileJava.options.encoding = 'UTF-8'
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
    repositories {
      jcenter()
    }
    
    dependencies {
    
      api 'com.google.guava:guava:28.2-jre'
      api 'com.google.code.gson:gson:2.8.6'
    
    
      annotationProcessor platform("io.micronaut:micronaut-bom:1.3.2")
      annotationProcessor "io.micronaut:micronaut-inject-java"
      implementation platform("io.micronaut:micronaut-bom:1.3.2")
      implementation "io.micronaut:micronaut-http-client"
      implementation "io.micronaut:micronaut-inject"
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      testImplementation 'org.junit.jupiter:junit-jupiter:5.5.2'
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      testImplementation 'org.hamcrest:hamcrest-library:1.3'
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      projectName = 'nshmp-lib'
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      gitTag = 'git describe --tags'.execute().text.replace('\n', '') ?: 'unknown'
    
      gitLink = '<a href="https://code.usgs.gov/ghsc/nshmp/nshmp-lib">' + gitTag +'</a>'
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      propsPath = '/resources/main/app.properties'
      docTitle = projectName + ': ' + gitLink
    }
    
    test {
    
      useJUnitPlatform()
    
    
      reports {
        junitXml.enabled = true
        html.enabled = true
      }
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      filter {
    
        includeTestsMatching "gov.usgs.earthquake.nshmp.EarthquakesTests"
        includeTestsMatching "gov.usgs.earthquake.nshmp.FaultsTests"
        includeTestsMatching "gov.usgs.earthquake.nshmp.MathsTests"
        includeTestsMatching "gov.usgs.earthquake.nshmp.data.*"
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
        includeTestsMatching "gov.usgs.earthquake.nshmp.eq.fault.*"
        includeTestsMatching "gov.usgs.earthquake.nshmp.eq.model.LoaderTests"
        includeTestsMatching "gov.usgs.earthquake.nshmp.eq.model.ModelConfigTests"
    
        includeTestsMatching "gov.usgs.earthquake.nshmp.geo.*"
        includeTestsMatching "gov.usgs.earthquake.nshmp.gmm.*"
        includeTestsMatching "gov.usgs.earthquake.nshmp.internal.*"
        includeTestsMatching "gov.usgs.earthquake.nshmp.mfd.*"
        includeTestsMatching "gov.usgs.earthquake.nshmp.tree.*"
    
    
        // TODO: Remove when updated
        excludeTestsMatching "gov.usgs.earthquake.nshmp.internal.NshmFaultSectionTests"
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      }
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    }
    
    jacocoTestReport {
      reports {
        xml.enabled true
    
        html.enabled true
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      }
    }
    
    javadoc {
      options.setUse(true)
      options.author(true)
      options.version(true)
      options.windowTitle(projectName)
      options.docTitle(docTitle)
      options.encoding('UTF-8')
      options.docEncoding('UTF-8')
      options.charSet('UTF-8')
      options.addStringOption('Xdoclint:none', '-quiet')
      options.links(
    
          'https://docs.oracle.com/javase/8/docs/api/',
          'https://google.github.io/guava/releases/26.0-jre/api/docs/')
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      include 'gov/usgs/earthquake/nshmp/**'
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    }
    
    /*
     * Enhance the jar task to build a fat jar if running the build
     * directly and add application version to a properties file.
     * Note that 'git describe' only works when running gradle from
     * the command line.
     */
    jar {
      doFirst {
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
        /* possible fat jar */
        if (rootProject.name == projectName) {
    
          from {
            configurations.compileClasspath.collect {
              it.isDirectory() ? it : zipTree(it).matching {
                exclude { it.path.contains('META-INF') }
              }
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
        /* record app version */
        def props = new Properties()
        def propsFile = new File(project.buildDir.toString() + propsPath)
        propsFile.getParentFile().mkdirs()
        propsFile.createNewFile()
        props.setProperty('app.version', gitTag)
        props.store(propsFile.newWriter(), null)
      }
    }
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    check.dependsOn jacocoTestReport
    
    /* Add HTML reports to SpotBugs */
    
    tasks.withType(com.github.spotbugs.SpotBugsTask) {
      reports {
        xml.enabled = false
        html.enabled = true
      }
    }