build.gradle
plugins {
id 'org.javacc.javacc'
id 'com.github.kt3k.coveralls'
id 'de.aaschmid.cpd'
id 'com.github.jk1.dependency-license-report'
}
repositories {
mavenCentral()
}
subprojects {
repositories {
mavenCentral()
}
apply plugin: 'java'
sourceCompatibility = gradle.javaSourceVersion
targetCompatibility = gradle.javaTargetVersion
sourceSets {
main.java.srcDirs = ['src', 'src-gen']
main.resources.srcDirs = ['res']
test.java.srcDirs = ['test-src']
test.resources.srcDirs = ['test-res']
}
compileJava {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:deprecation"
if (JavaVersion.current().isJava9Compatible()) {
options.release = gradle.javaReleaseVersion
}
}
apply plugin: 'org.javacc.javacc'
compileJavacc {
inputDirectory = file('javacc')
outputDirectory = file('src-gen')
include '**/*.jj'
arguments = [grammar_encoding: 'UTF-8', static: 'false']
}
task cleanJavacc(type: Delete) {
delete compileJavacc.outputDirectory
}
apply plugin: 'java-library'
configurations {
lib
}
dependencies {
lib fileTree(dir: gradle.libDir, include: ['**/*.jar'])
configurations.api.extendsFrom(configurations.lib)
testImplementation gradle.junit
testRuntimeOnly gradle.junit
javacc gradle.javacc
}
test {
useJUnitPlatform()
workingDir = rootDir
testLogging {
events "failed"
exceptionFormat "full"
// Uncomment the next two lines to show stdout and stderr of tests
/* outputs.upToDateWhen {false} */
/* showStandardStreams = true */
}
}
apply plugin: 'checkstyle'
checkstyle {
toolVersion = gradle.checkstyleVersion
configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml")
}
checkstyleMain.exclude gradle.javaccExclude
task checkstyle(dependsOn: tasks.withType(Checkstyle)*.name)
apply plugin: 'pmd'
pmd {
toolVersion = gradle.pmdVersion
consoleOutput = true
incrementalAnalysis = true
ruleSetFiles = files("${project.rootDir}/config/pmd/rules.xml")
ruleSets = []
}
pmdMain.exclude gradle.javaccExclude
task pmd(dependsOn: tasks.withType(Pmd)*.name)
apply plugin: 'de.aaschmid.cpd'
cpd {
toolVersion = gradle.pmdVersion
minimumTokenCount = 250
}
cpdCheck {
dependsOn compileJavacc
source = sourceSets.main.allJava
exclude gradle.javaccExclude
}
apply plugin: 'jacoco'
jacoco {
toolVersion = gradle.jacocoVersion
}
jacocoTestReport {
reports {
xml.required = true /* XML report for coveralls */
html.required = false /* skip human readable report */
}
}
afterEvaluate {project ->
task copyLibs(type: Copy) {
from configurations.lib
into "$buildDir/$gradle.libDir"
include '*.jar'
}
jar {
dependsOn copyLibs
destinationDirectory = file("$buildDir/bin")
manifest {
attributes 'Class-Path': configurations.lib.collect {
"../$gradle.libDir/" + it.name
}.join(' ')
}
}
}
apply plugin: 'eclipse'
eclipse {
classpath {
defaultOutputDir = file('build/eclipse/bin/')
file.whenMerged {
entries.each {
if (it.kind == 'src' && it.hasProperty('output')) {
it.output = it.output.replace('bin/', 'build/eclipse/')
}
}
}
}
}
eclipseClasspath.dependsOn compileJavacc
apply plugin: 'idea'
idea.module {
sourceDirs = [file('src'), file('javacc'), file('src-gen')]
generatedSourceDirs = [file('src-gen')]
resourceDirs = [file('res'), file('models')]
testSourceDirs = [file('test-src')]
testResourceDirs = [file('test-res')]
excludeDirs = [file('.gradle'), file('.settings'), file('bin'), file('build'), file('gradle')]
inheritOutputDirs = false
outputDir = file('build/idea/')
}
ideaModule.dependsOn compileJavacc
task cleanAll(dependsOn: ['clean', 'cleanEclipse', 'cleanIdea', 'cleanJavacc'])
}
apply plugin: 'java'
cpdCheck {
dependsOn compileJavacc
source = sourceSets.main.allJava
exclude gradle.javaccExclude
}
apply plugin: 'jacoco'
jacoco {
toolVersion = gradle.jacocoVersion
}
def coverageProjects = subprojects.findAll {
it.name ==~ ~(gradle.coverageProjects.join('|'))
}
task jacocoRootReport(type: JacocoReport) {
dependsOn(coverageProjects.test)
evaluationDependsOnChildren()
sourceDirectories.from = coverageProjects.sourceSets.main.allSource.srcDirs
additionalSourceDirs.from = coverageProjects.sourceSets.main.allSource.srcDirs
classDirectories.from = coverageProjects.sourceSets.main.output
executionData.from = coverageProjects.jacocoTestReport.executionData
reports {
xml.required = true // XML report for coveralls
html.required = true // human readable report
}
afterEvaluate {
ext.jacocoExclude = [gradle.javaccExclude]
subprojects {
if (it.hasProperty('excludeFromCoverage')) {
jacocoExclude += it.excludeFromCoverage
}
}
classDirectories.from = classDirectories.files.collect {
fileTree(dir: it, exclude: jacocoExclude)
}
}
doLast {
println 'Excluding from coverage:'
jacocoExclude.each { println " - " + it }
}
}
coveralls {
sourceDirs = coverageProjects.sourceSets.main.allSource.srcDirs.flatten()
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"
}
tasks.coveralls {
group = 'Verification'
description = 'Generate coverage report for all subprojects with tests.'
dependsOn jacocoRootReport
}
apply plugin: 'com.github.jk1.dependency-license-report'
import com.github.jk1.license.filter.*
licenseReport {
configurations = ['runtimeClasspath', 'compileClasspath']
renderers = [new com.github.jk1.license.render.InventoryHtmlReportRenderer()]
allowedLicensesFile = new File("${project.rootDir}/config/license/allowed.json")
filters = [new ReduceDuplicateLicensesFilter(), new LicenseBundleNormalizer()]
}
checkLicense.group = 'Verification'
generateLicenseReport.group = 'Verification'
checkLicensePreparation.group = null
// License checking takes too long (>2min), has deprecated calls and may run out of memory
/* check.dependsOn checkLicense */
apply plugin: 'idea'
idea.module {
excludeDirs = [file('.gradle'), file('config'), file('dist-template'), file('doc'), file('gradle')]
outputDir = file('build/idea/')
}
def workcraftRunConfiguration = '''
<configuration default="false" name="Workcraft" type="Application" factoryName="Application" singleton="true">
<option name="MAIN_CLASS_NAME" value="org.workcraft.Console" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<module name="WorkcraftRunner" />
</configuration>
'''
idea.workspace.iws {
withXml { workspace ->
def runManagerNode = workspace.node.component.find { it.@name == 'RunManager' }
def workcraftRunNode = runManagerNode.find { it.@name == 'Workcraft' }
if (workcraftRunNode != null) runManagerNode?.remove(workcraftRunNode)
runManagerNode?.append(new XmlParser().parseText(workcraftRunConfiguration))
}
}
tasks.cleanIdea.doLast {
project.delete 'workcraft.iws'
}
task cleanAll(dependsOn: 'cleanIdea')
allprojects {
javadoc.group = null // Exclude javadoc from the list of tasks
}
tasks.cleanAll.doLast {
project.delete 'build/' // Remove root build directory (left untouched by other clean tasks)
}