plugins { id "com.jfrog.bintray" version "1.7.3" } apply plugin: 'java' apply plugin: 'idea' apply plugin: 'maven' apply plugin: 'maven-publish' 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' def mavenName = 'SemVer' def mavenDescription = 'Semantic Version Annotation Processor' def mavenUrl = 'https://github.com/ethauvin/semver' def mavenLicense = 'The BSD 3-Clause License' def mavenLicenseUrl = 'http://opensource.org/licenses/BSD-3-Clause' def mavenScmCon = 'https://github.com/ethauvin/semver.git' def mavenScmDevCon = 'git@github.com:ethauvin/semver.git' def pkgLicenses = ['BSD 3-Clause'] def pkgIssueTrackerUrl = mavenUrl + '/issues' def pkgLabels = ['java', 'annotation', 'processor', 'semantic', 'version'] [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' repositories { mavenLocal() jcenter() } dependencies { compile 'com.github.spullara.mustache.java:compiler:0.9.4' testCompile 'org.testng:testng:6.11' } bintray { user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') publications = ['MyPublication'] dryRun = true pkg { repo = 'maven' name = mavenName licenses = pkgLicenses desc = mavenDescription websiteUrl = mavenUrl issueTrackerUrl = pkgIssueTrackerUrl vcsUrl = mavenScmCon labels = pkgLabels publicDownloadNumbers = true version { name = project.version desc = 'Version ' + project.version vcsTag = project.version gpg { sign = true } } } } def pomConfig = { licenses { license { name mavenLicense url mavenLicenseUrl distribution 'repo' } } developers { developer { id 'ethauvin' name 'Erik C. Thauvin' email 'erik@thauvin.net' } } scm { connection 'scm:git:' + mavenScmCon developerConnection 'scm:git:' + mavenScmDevCon url mavenScmCon } } publishing { publications { MyPublication(MavenPublication) { from components.java artifact sourcesJar artifact javadocJar groupId mavenGroupId artifactId rootProject.name version project.version pom.withXml { def root = asNode() root.appendNode('name', mavenName) root.appendNode('description', mavenDescription) root.appendNode('url', mavenUrl) root.children().last() + pomConfig } } } } task javadocJar(type: Jar, dependsOn: javadoc) { group = 'Build' description = 'Builds an archive of the javadoc docs.' classifier = 'javadoc' from javadoc.destinationDir } task sourcesJar(type: Jar) { group = 'Build' description = 'Builds an archive of the source code.' classifier = 'sources' from sourceSets.main.allSource } artifacts { archives javadocJar archives sourcesJar } javadoc { title = mavenDescription + ' ' + version options.tags = ['created'] options.author = true options.addStringOption('link', 'http://docs.oracle.com/javase/8/docs/api/') //options.addStringOption('sourcepath', project.hasProperty('jdkSrc') ? jdkSrc : "$System.env.JAVA_HOME/src.zip") if (JavaVersion.current().isJava8Compatible()) { options.addStringOption('Xdoclint:none', '-quiet') } } 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 } task wrapper(type: Wrapper) { gradleVersion = gradle.gradleVersion } task release(dependsOn: ['wrapper', 'clean', 'deploy']) { doLast { group = 'Publishing' description = 'Releases new version.' isRelease = true } } task pandoc(type: Exec) { group = 'Documentation' def pandoc_args = ['--from', 'markdown_github', '--to', 'html5', '-s', '-c', 'github-pandoc.css', '-o', 'README.html', 'README.md'] if (Os.isFamily(Os.FAMILY_WINDOWS)) { commandLine(['cmd', '/c', 'pandoc'] + pandoc_args) } else { executable 'pandoc' args pandoc_args } standardOutput = new ByteArrayOutputStream() ext.output = { return standardOutput.toString() } }