build.gradle 2.77 KB
/*
 * This software is in the public domain under CC0 1.0 Universal plus a 
 * Grant of Patent License.
 * 
 * To the extent possible under law, the author(s) have dedicated all
 * copyright and related and neighboring rights to this software to the
 * public domain worldwide. This software is distributed without any
 * warranty.
 * 
 * You should have received a copy of the CC0 Public Domain Dedication
 * along with this software (see the LICENSE.md file). If not, see
 * <http://creativecommons.org/publicdomain/zero/1.0/>.
 */

apply plugin: 'groovy'

def componentNode = parseComponent(project)
version = componentNode.'@version'
def jarBaseName = componentNode.'@name'
def moquiDir = projectDir.parentFile.parentFile.parentFile
def frameworkDir = file(moquiDir.absolutePath + '/framework')

repositories {
    flatDir name: 'localLib', dirs: frameworkDir.absolutePath + '/lib'
    mavenCentral()
}

// Log4J has annotation processors, disable to avoid warning
tasks.withType(JavaCompile) { options.compilerArgs << "-proc:none" }
tasks.withType(GroovyCompile) { options.compilerArgs << "-proc:none" }

dependencies {
    // Only compile against framework, don't include it in the component
    compileOnly project(':framework')

    // Servlet API (provided by framework, but needed for compilation)
    compileOnly 'javax.servlet:javax.servlet-api:4.0.1'
    
    // Test dependencies
    testImplementation project(':framework')
    testImplementation project(':framework').configurations.testImplementation.allDependencies
}

// by default the Java plugin runs test on build, change to not do that (only run test if explicit task)
check.dependsOn.clear()

test {
    useJUnitPlatform()
    testLogging { events "passed", "skipped", "failed" }
    testLogging.showStandardStreams = true
    testLogging.showExceptions = true
    maxParallelForks 1

    dependsOn cleanTest

    systemProperty 'moqui.runtime', moquiDir.absolutePath + '/runtime'
    systemProperty 'moqui.conf', 'conf/MoquiDevConf.xml'
    systemProperty 'moqui.init.static', 'true'
    maxHeapSize = "512M"

    classpath += files(sourceSets.main.output.classesDirs)
    // filter out classpath entries that don't exist (gradle adds a bunch of these), or ElasticSearch JarHell will blow up
    classpath = classpath.filter { it.exists() }

    beforeTest { descriptor -> logger.lifecycle("Running test: ${descriptor}") }
}

task cleanLib(type: Delete) { delete fileTree(dir: projectDir.absolutePath+'/lib', include: '*') }
clean.dependsOn cleanLib

jar {
    destinationDirectory = file(projectDir.absolutePath + '/lib')
    archiveBaseName = jarBaseName
}
task copyDependencies { doLast {
    copy { from configurations.runtimeClasspath
        into file(projectDir.absolutePath + '/lib') }
} }
copyDependencies.dependsOn cleanLib
jar.dependsOn copyDependencies