Skip to content
Snippets Groups Projects
build.gradle 3.54 KiB
Newer Older
Powers, Peter M.'s avatar
Powers, Peter M. committed

apply plugin: 'java'
Powers, Peter M.'s avatar
Powers, Peter M. committed
apply plugin: 'jacoco'
apply plugin: 'eclipse-wtp'
Powers, Peter M.'s avatar
Powers, Peter M. committed

sourceCompatibility = 1.8
Powers, Peter M.'s avatar
Powers, Peter M. committed
compileJava.options.encoding = 'UTF-8'
Powers, Peter M.'s avatar
Powers, Peter M. committed
repositories {
  jcenter()
}

dependencies {
Powers, Peter M.'s avatar
Powers, Peter M. committed
  compile('com.google.guava:guava:24.1-jre') {
Powers, Peter M.'s avatar
Powers, Peter M. committed
    /* skip optional guava dependencies */
Powers, Peter M.'s avatar
Powers, Peter M. committed
    transitive = false
  }
Powers, Peter M.'s avatar
Powers, Peter M. committed
  compile 'com.google.code.gson:gson:2.8.2'
Powers, Peter M.'s avatar
Powers, Peter M. committed
  testCompile 'junit:junit:4.12'
}

sourceSets {
  main {
    java {
      srcDirs = ['src']
    }
    resources {
      srcDirs = ['src']
      exclude '**/*.java'
    }
  }
  test {
    java {
Powers, Peter M.'s avatar
Powers, Peter M. committed
      srcDirs = ['test']
Powers, Peter M.'s avatar
Powers, Peter M. committed
    }
Powers, Peter M.'s avatar
Powers, Peter M. committed
    resources {
      srcDirs = ['test']
      exclude '**/*.java'
    }
Powers, Peter M.'s avatar
Powers, Peter M. committed
ext {
  projectName = 'nshmp-haz'
  /* 
   * The git-dir option gets the correct tag when
   * build is called from nshmp-haz-ws.
   */
  gitCommand = 'git --git-dir=../nshmp-haz/.git describe --tags'
  gitTag = gitCommand.execute().text.replace('\n', '') ?: 'unknown'
Powers, Peter M.'s avatar
Powers, Peter M. committed
  gitLink = '<a href="https://github.com/usgs/nshmp-haz">' + gitTag +'</a>'
Powers, Peter M.'s avatar
Powers, Peter M. committed
  propsPath = '/resources/main/app.properties'
Powers, Peter M.'s avatar
Powers, Peter M. committed
  docTitle = projectName + ': ' + gitLink
  docFooter = '<div style="float: left; font-size: 16px; text-align: right; ' +
    'padding: 10px; width: 100%; box-sizing: border-box; background-color: #f9f9f9">' +
    '<b><a href="https://www.usgs.gov" target="_top">U.S. Geological Survey</a></b> ' + 
    '– National Seismic Hazard Mapping Project ' +
    '(<a href="https://earthquake.usgs.gov/hazards/" target="_top">NSHMP</a>) ' +
    '– <a href="https://github.com/usgs/nshmp-haz/blob/master/LICENSE.md" ' +
    'target="_top">License</a> | <b>' + gitLink + '</b></div>'
Powers, Peter M.'s avatar
Powers, Peter M. committed
  docOut = findProperty('javadoc_loc')
Powers, Peter M.'s avatar
Powers, Peter M. committed
}

test {
  //include 'gov/usgs/earthquake/nshmp/gmm/*'
  //exclude 'gov/usgs/earthquake/nshmp/**'
  //include 'gov/usgs/earthquake/nshmp/gmm/CeusSoftRock.class'
  filter {
    includeTestsMatching "gov.usgs.earthquake.nshmp.data.*"
  }
}

jacocoTestReport {
  reports {
    xml.enabled true
    html.enabled true
  }
}


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.bottom(docFooter)
  options.addStringOption('Xdoclint:none', '-quiet')
  options.links(
    'https://docs.oracle.com/javase/8/docs/api/',
    'https://google.github.io/guava/releases/23.0/api/docs/',
    'https://google.github.io/gson/apidocs/')
  include 'gov/usgs/earthquake/nshmp/**'
  exclude 'gov/usgs/earthquake/nshmp/etc/**'
  exclude 'gov/usgs/earthquake/nshmp/gcim/**'
  exclude 'gov/usgs/earthquake/nshmp/internal/**'
Powers, Peter M.'s avatar
Powers, Peter M. committed
  doLast {
    if (docOut) {
      delete docOut
      copy {
        from 'build/docs/javadoc'
        into docOut
      }
      copy {
        from 'etc/resources/docs'
        into docOut + '/resources'
      }
    }
  }
Powers, Peter M.'s avatar
Powers, Peter M. 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.
Powers, Peter M.'s avatar
Powers, Peter M. committed
jar {
  doFirst {
Powers, Peter M.'s avatar
Powers, Peter M. committed
    /* possible fat jar */
    if (rootProject.name == projectName) {
      from { configurations.compile.collect {
Powers, Peter M.'s avatar
Powers, Peter M. committed
        it.isDirectory() ? it : zipTree(it).matching {
Powers, Peter M.'s avatar
Powers, Peter M. committed
          exclude { it.path.contains('META-INF') }
Powers, Peter M.'s avatar
Powers, Peter M. committed
        }
Powers, Peter M.'s avatar
Powers, Peter M. committed
      }}
Powers, Peter M.'s avatar
Powers, Peter M. committed
    }
Powers, Peter M.'s avatar
Powers, Peter M. committed
    
    /* record app version */
    def props = new Properties()
Powers, Peter M.'s avatar
Powers, Peter M. committed
    def propsFile = new File(project.buildDir.toString() + propsPath)
Powers, Peter M.'s avatar
Powers, Peter M. committed
    propsFile.createNewFile()
    props.setProperty('app.version', gitTag)
    props.store(propsFile.newWriter(), null)
Powers, Peter M.'s avatar
Powers, Peter M. committed
  }
}