Skip to content
Snippets Groups Projects
build.gradle 5.51 KiB
Newer Older
  • Learn to ignore specific revisions
  •  * In order to build and run services locally,
     * one needs to include the following directorie(s) in the root project (they
    
     * are ignored by git):
     *
    
     *    models/
     *       ak/
     *          2007/
     *       wus/
     *          2008/
     *          2014/
     *          2014b/
     *          2018/
     *       ceus/
     *          2008/
     *          2014/
     *          2018/
    
     *
     * ...with each 'year' directory being an alias to the corresponding
    
     * git repository. One only needs to include the model they will run in the services.
     *
     * Then build the JAR file: ./gradlew assemble
     *
     * One can then specify the model to run in the services:
     *    java -jar build/libs/nshmp-haz-v2-all.jar -model=<MODEL>
     *
     * Where <MODEL> is one of the model enums in nshmp.www.Model
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    
    
    plugins {
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      id "eclipse-wtp"
      id "jacoco"
      id "war"
      id "application"
    
      id "com.star-zero.gradle.githook" version "1.2.0"
      id "com.github.spotbugs" version "3.0.0"
      id "com.diffplug.gradle.spotless" version "3.27.1"
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      id "com.github.johnrengelman.shadow" version "5.2.0"
      id "net.ltgt.apt-eclipse" version "0.21"
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    
    
    apply from: "${projectDir}/gradle/ext.gradle"
    apply from: "${projectDir}/gradle/jar.gradle"
    apply from: "${projectDir}/gradle/javadoc.gradle"
    apply from: "${projectDir}/gradle/tasks.gradle"
    
    
    sourceCompatibility = JavaVersion.VERSION_11
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    compileJava.options.encoding = "UTF-8"
    
    mainClassName = "gov.usgs.earthquake.nshmp.www.Application"
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    jacoco {
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      toolVersion = "0.8.4"
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    repositories {
      jcenter()
    }
    
    
    git {
      implementation("git@code.usgs.gov:ghsc/nshmp/nshmp-lib.git", {
        name "nshmp-haz-dep--nshmp-lib"
        tag "v0.0.4"
      })
    }
    
    apply from: "${nshmpLibGradleDir}/git-hooks.gradle"
    apply from: "${nshmpLibGradleDir}/spotbugs.gradle"
    apply from: "${nshmpLibGradleDir}/spotless.gradle"
    
    dependencies {
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      // AWS
      implementation "com.amazonaws:aws-lambda-java-core:${awsLambdaCoreVersion}"
      implementation "com.amazonaws:aws-java-sdk-lambda:${awsLambdaVersion}"
      implementation "com.amazonaws:aws-java-sdk-s3:${awsS3Version}"
      implementation "com.amazonaws:aws-java-sdk-ec2:${awsEc2Version}"
    
      // Micronaut
      annotationProcessor platform("io.micronaut:micronaut-bom:${mnVersion}")
      annotationProcessor "io.micronaut:micronaut-inject-java"
      annotationProcessor "io.micronaut:micronaut-validation"
      implementation platform("io.micronaut:micronaut-bom:${mnVersion}")
      implementation "io.micronaut:micronaut-http-client"
      implementation "io.micronaut:micronaut-inject"
      implementation "io.micronaut:micronaut-validation"
      implementation "io.micronaut:micronaut-runtime"
      implementation "io.micronaut:micronaut-http-server-netty"
      implementation "com.fasterxml.jackson.module:jackson-module-parameter-names:${jacksonVersion}"
      runtimeOnly "ch.qos.logback:logback-classic:${logbackVersion}"
    
      // Swagger
      annotationProcessor("io.micronaut.configuration:micronaut-openapi:${mnOpenAPIVersion}")
      implementation("io.swagger.core.v3:swagger-annotations:${swaggerVersion}")
      implementation("io.swagger.core.v3:swagger-models:${swaggerVersion}")
    
      // junit
      testAnnotationProcessor "io.micronaut:micronaut-inject-java:${mnVersion}"
      testImplementation platform("io.micronaut:micronaut-bom:${mnVersion}")
      testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
      testImplementation "org.junit.jupiter:junit-jupiter-api"
      testImplementation "io.micronaut.test:micronaut-test-junit5"
      testImplementation "io.micronaut.test:micronaut-test-spock"
      testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    test {
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      useJUnitPlatform()
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
      filter {
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
        includeTestsMatching "gov.usgs.earthquake.nshmp.programs.*"
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
      }
    }
    
    jacocoTestReport {
      reports {
        xml.enabled true
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
        html.enabled true
    
        classDirectories.from(files(classDirectories.files.collect {
    
              dir: it,
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
              exclude: ["**/etc/**"])
    
    Powers, Peter M.'s avatar
    Powers, Peter M. committed
    check.dependsOn jacocoTestReport
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    shadowJar {
      mergeServiceFiles()
    }
    
    tasks.withType(JavaCompile) {
      options.encoding = "UTF-8"
      options.compilerArgs.add("-parameters")
    }
    
    tasks.withType(JavaExec) {
      jvmArgs('-noverify', '-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote')
    }
    
    
    /**
     * Create war file with production models
     */
    war {
      enabled = true
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      webAppDirName = "webapp"
    
      dependsOn jar
    
       * Exclude existing models directory with symlinks
       * to support Eclipse deployments.
       */
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      exclude "models"
    
    
      prod_models.each{model ->
        from(model[0]) { into model[1] }
      }
    
    
      doFirst {
        /* Record service and model versions */
        writeProperties()
      }
    }
    
    
    /**
     * Create properties file
     */
    def writeProperties() {
      def props = new Properties()
      def propsFile = new File(project.buildDir.toString() + propsPath)
      propsFile.createNewFile()
      props.setProperty('app.version', getGitTag('.'))
      props.setProperty('E2007.version', getGitTag(repo_ak_2007))
      props.setProperty('E2008.version', getGitTag(repo_cous_2008))
      props.setProperty('E2014.version', getGitTag(repo_cous_2014))
      props.setProperty('E2014B.version', getGitTag(repo_cous_2014b))
      props.setProperty('E2018.version', getGitTag(repo_cous_2018))
    
      props.setProperty('E2020.version', getGitTag(repo_hi_2020))
    
      props.store(propsFile.newWriter(), null)
    }
    
    /*
     * Update XML formatting
     */
    
    spotless {
    
      /* XML formatting */
    
      format "xml", {
        target fileTree(".") {
          include "**/*.xml"
    
          exclude "**/build/**", ".settings/**", "**/models/**"
    
    
    /* Add HTML reports to SpotBugs */
    tasks.withType(com.github.spotbugs.SpotBugsTask) {
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
      ignoreFailures = false // TODO remove when nshmp-lib is updated
    
      reports {
        xml.enabled = false
        html.enabled = true
      }
    }