build.gradle

  1apply plugin: 'java'
  2apply plugin: 'eclipse'
  3apply plugin: 'maven'
  4apply plugin: 'osgi'
  5apply plugin: 'signing'
  6
  7ext {
  8	shortVersion = '0.1'
  9	isSnapshot = true
 10	gitCommit = getGitCommit()
 11	isReleaseVersion = !shortVersion
 12	sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')
 13	signingRequired = isReleaseVersion
 14	sonatypeSnapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
 15	sonatypeStagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
 16	buildDate = (new java.text.SimpleDateFormat("yyyy-MM-dd")).format(new Date())
 17}
 18
 19group = 'de.measite.minidns'
 20description = "A minimal DNS client library with support for A, AAAA, NS and SRV records"
 21sourceCompatibility = 1.7
 22version = shortVersion
 23if (isSnapshot) {
 24	version += '-SNAPSHOT'
 25}
 26
 27repositories {
 28	mavenLocal()
 29	mavenCentral()
 30	maven {
 31		url 'https://oss.sonatype.org/content/repositories/snapshots/'
 32	}
 33}
 34
 35dependencies {
 36	compile 'org.igniterealtime.jxmpp:jxmpp-util-cache:0.1.0-alpha1-SNAPSHOT'
 37}
 38
 39jar {
 40	manifest {
 41		instruction 'Implementation-GitRevision:', project.ext.gitCommit
 42	}
 43}
 44
 45gradle.taskGraph.whenReady { taskGraph ->
 46	if (signingRequired
 47		&& taskGraph.allTasks.any { it instanceof Sign }) {
 48		// Use Java 6's console to read from the console (no good for a CI environment)
 49		Console console = System.console()
 50		console.printf '\n\nWe have to sign some things in this build.\n\nPlease enter your signing details.\n\n'
 51		def password = console.readPassword('GnuPG Private Key Password: ')
 52
 53		allprojects { ext.'signing.password' = password }
 54
 55		console.printf '\nThanks.\n\n'
 56	}
 57}
 58
 59uploadArchives {
 60	repositories {
 61		mavenDeployer {
 62			if (signingRequired) {
 63				beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
 64			}
 65			repository(url: project.sonatypeStagingUrl) {
 66				if (sonatypeCredentialsAvailable) {
 67					authentication(userName: sonatypeUsername, password: sonatypePassword)
 68				}
 69			}
 70			snapshotRepository(url: project.sonatypeSnapshotUrl) {
 71				if (sonatypeCredentialsAvailable) {
 72					authentication(userName: sonatypeUsername, password: sonatypePassword)
 73				}
 74			}
 75
 76			pom.project {
 77				name 'minidns'
 78				packaging 'jar'
 79				inceptionYear '2014'
 80				url 'https://github.com/rtreffer/minidns'
 81				description project.description
 82
 83				issueManagement {
 84					system 'GitHub'
 85					url 'https://github.com/rtreffer/minidns/issues'
 86				}
 87
 88				distributionManagement {
 89					snapshotRepository {
 90						id 'minidns.snapshot'
 91						url project.sonatypeSnapshotUrl
 92					}
 93				}
 94
 95				scm {
 96					url 'https://github.com/rtreffer/minidns'
 97					connection 'scm:git:https://github.com/rtreffer/minidns.git'
 98					developerConnection 'scm:git:https://github.com/rtreffer/minidns.git'
 99				}
100
101				licenses {
102					license {
103						name 'The Apache Software License, Version 2.0'
104						url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
105						distribution 'repo'
106					}
107				}
108
109				developers {
110					developer {
111						id 'rtreffer'
112						name 'Rene Treffer'
113					}
114					developer {
115						id 'flow'
116						name 'Florian Schmaus'
117						email 'flow@geekplace.eu'
118					}
119				}
120			}
121		}
122	}
123	signing {
124		required { signingRequired }
125		sign configurations.archives
126	}
127}
128
129def getGitCommit() {
130	def dotGit = new File("$projectDir/.git")
131	if (!dotGit.isDirectory()) return 'non-git build'
132
133	def cmd = 'git describe --all --dirty=+'
134	def proc = cmd.execute()
135	def gitCommit = proc.text.trim()
136	assert !gitCommit.isEmpty()
137	gitCommit
138}