apply plugin: 'java' apply plugin: 'idea' apply plugin: 'maven' import org.apache.tools.ant.taskdefs.condition.Os defaultTasks 'deploy' def getVersion(isIncrement = false) { def propsFile = 'version.properties' def majorKey = 'version.major' def minorKey = 'version.minor' def patchKey = 'version.patch' def metaKey = 'version.buildmeta' def preKey = 'version.prerelease' if (isIncrement) { ant.propertyfile(file: propsFile) { entry(key: patchKey, type: 'int', default: '-1', operation: '+') } } def p = new Properties() file(propsFile).withInputStream { stream -> p.load(stream) } def metadata = p.getProperty(metaKey, '') def prerelease = p.getProperty(preKey, '') return (p.getProperty(majorKey, '1') + '.' + p.getProperty(minorKey, '0') + '.' + p.getProperty(patchKey, '0') + (prerelease.length() > 0 ? '-' + prerelease : '') + (metadata.length() > 0 ? '+' + metadata : '')) } version = getVersion() def deployDir = 'deploy' def isRelease = 'release' in gradle.startParameter.taskNames def mavenGroupId = 'net.thauvin.erik' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' repositories { mavenLocal() mavenCentral() } dependencies { compile 'org.apache.velocity:velocity:1.7' testCompile 'org.testng:testng:+' } test { useTestNG() } compileJava { doFirst { project.version = getVersion(isRelease) } } clean { delete deployDir } task copyToDeploy(type: Copy) { from jar into deployDir } task deploy(dependsOn: ['build', 'copyToDeploy']) { description = 'Copies all needed files to the ${deployDir} directory.' group = 'Publishing' outputs.dir deployDir inputs.files copyToDeploy mustRunAfter clean } uploadArchives { repositories { mavenDeployer { repository(url: mavenLocal().url) pom.artifactId = rootProject.name pom.groupId = mavenGroupId } } } task wrapper(type: Wrapper) { gradleVersion = gradle.gradleVersion } task release(dependsOn: ['deploy', 'wrapper', 'uploadArchives']) << { group = 'Publishing' description = 'Releases new version.' isRelease = true } task pandoc(type: Exec) { group = 'Documentation' def pandoc_args = ['--from', 'markdown_github', '--to', 'html5', '-s', '-o', 'README.html', 'README.md'] if (Os.isFamily(Os.FAMILY_WINDOWS)) { commandLine(['cmd', '/c', 'pandoc'] + pandoc_args) } else { executable '/usr/local/bin/pandoc' args pandoc_args } standardOutput = new ByteArrayOutputStream() ext.output = { return standardOutput.toString() } }