Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
342 lines (298 sloc) 9.72 KB
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1"
}
}
plugins {
id 'ru.vyarus.animalsniffer' version '1.4.3'
}
apply from: 'version.gradle'
allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'osgi'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
group = 'org.minidns'
description = "A minimal DNS client library with support for A, AAAA, NS and SRV records"
sourceCompatibility = 1.7
version = shortVersion
ext {
junitVersion = 4.11
androidBootClasspath = getAndroidRuntimeJar(minidnsMinAndroidSdk)
rootConfigDir = new File(rootDir, 'config')
gitCommit = getGitCommit()
builtDate = (new java.text.SimpleDateFormat("yyyy-MM-dd")).format(new Date())
isReleaseVersion = !isSnapshot
signingRequired = isReleaseVersion
sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')
sonatypeSnapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
sonatypeStagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
}
if (isSnapshot) {
version = version + '-SNAPSHOT'
}
if (!ext.isSnapshot && !'git describe --exact-match HEAD'.execute().text.trim().equals(ext.shortVersion)) {
throw new org.gradle.api.InvalidUserDataException('Untagged version detected! Please tag every release.')
}
if (!version.endsWith('-SNAPSHOT') && version != 'git tag --points-at HEAD'.execute().text.trim()) {
throw new org.gradle.api.InvalidUserDataException(
'Tag mismatch detected, version is ' + version + ' but should be ' +
'git tag --points-at HEAD'.execute().text.trim())
}
repositories {
mavenLocal()
mavenCentral()
}
tasks.withType(JavaCompile) {
// Some systems may not have set their platform default
// converter to 'utf8', but we use unicode in our source
// files. Therefore ensure that javac uses unicode
options.encoding = "utf8"
options.compilerArgs = [
'-Xlint:all',
// Set '-options' because a non-java7 javac will emit a
// warning if source/traget is set to 1.7 and
// bootclasspath is *not* set.
// TODO implement a sound heuristic to determine a java7
// rt.jar on the build host. And if none is found,
// fallback to using a environment variable,
// e.g. JAVA7_HOME. See SMACK-651.
'-Xlint:-options',
'-Werror',
]
}
checkstyle {
configFile = new File(rootConfigDir, 'checkstyle.xml')
}
jacoco {
toolVersion = "0.8.1"
}
jacocoTestReport {
dependsOn test
sourceDirectories = project.files(sourceSets.main.allSource.srcDirs)
classDirectories = project.files(sourceSets.main.output)
reports {
xml.enabled true
}
}
eclipse {
classpath {
downloadJavadoc = true
}
}
// Make all project's 'test' targets depend on javadoc, so that
// javadoc is also linted.
test.dependsOn javadoc
if (JavaVersion.current().isJava8Compatible()) {
tasks.withType(Javadoc) {
// The '-quiet' as second argument is actually a hack,
// since the one paramater addStringOption doesn't seem to
// work, we extra add '-quiet', which is added anyway by
// gradle.
// See https://github.com/gradle/gradle/issues/2354
options.addStringOption('Xdoclint:all', '-quiet')
// Abort on javadoc warnings.
// See JDK-8200363 (https://bugs.openjdk.java.net/browse/JDK-8200363)
// for information about the -Xwerror option.
options.addStringOption('Xwerror', '-quiet')
}
}
}
subprojects {
apply plugin: 'maven'
apply plugin: 'signing'
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
task testJar(type: Jar, dependsOn: testClasses) {
classifier = 'tests'
from sourceSets.test.output
}
artifacts {
archives sourcesJar
archives javadocJar
archives testJar
}
uploadArchives {
repositories {
mavenDeployer {
if (signingRequired) {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
}
repository(url: project.sonatypeStagingUrl) {
if (sonatypeCredentialsAvailable) {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
}
snapshotRepository(url: project.sonatypeSnapshotUrl) {
if (sonatypeCredentialsAvailable) {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
}
pom.project {
name 'minidns'
description 'A DNS library for Java and Android systems'
url 'https://github.com/minidns/minidns'
inceptionYear '2014'
scm {
url 'https://github.com/minidns/minidns'
connection 'scm:https://github.com/minidns/minidns'
developerConnection 'scm:git://github.com/minidns/minidns.git'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'rtreffer'
name 'Rene Treffer'
email 'treffer@measite.de'
}
developer {
id 'flow'
name 'Florian Schmaus'
email 'flow@geekplace.eu'
}
}
}
}
}
}
signing {
required { signingRequired }
sign configurations.archives
}
}
configure(subprojects.findAll{!it.name.endsWith('-java7') && !it.name.endsWith('-android21')}) {
apply plugin: 'ru.vyarus.animalsniffer'
dependencies {
signature "net.sf.androidscents.signature:android-api-level-${minidnsMinAndroidSdk}:2.3.1_r2@signature"
}
animalsniffer {
sourceSets = [sourceSets.main]
}
}
gradle.taskGraph.whenReady { taskGraph ->
if (signingRequired
&& taskGraph.allTasks.any { it instanceof Sign }) {
// Use Java 6's console to read from the console (no good for a CI environment)
def console = System.console()
if (console == null) {
throw new Exception("Could not obtain system console (Console is 'null'). Did you build with gradle daemon? Try the same Gradle command with \"--no-daemon\".")
}
console.printf '\n\nWe have to sign some things in this build.\n\nPlease enter your signing details.\n\n'
def password = console.readPassword('GnuPG Private Key Password: ')
allprojects { ext.'signing.password' = password }
console.printf '\nThanks.\n\n'
}
}
jar {
// Root project should not create empty jar artifact
enabled = false
}
// Disable upload archives for the root project
uploadArchives {
enabled = false
}
apply plugin: "com.github.kt3k.coveralls"
coveralls {
sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath
}
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn = subprojects.jacocoTestReport
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories = files(subprojects.sourceSets.main.output)
executionData = files(subprojects.jacocoTestReport.executionData)
reports {
xml.enabled true
xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
}
// We could remove the following setOnlyIf line, but then
// jacocoRootReport would silently be SKIPPED if something with
// the subprojects is wrong (e.g. a project is missing
// in there).
setOnlyIf { true }
}
task integrationTest {
// Depend on the integration test's 'run' task using a closure, as
// usually the subprojects are evaluated after the parent
// project. The closure defers the lookup, compared to
// dependsOn project(':minidns-integration-test').tasks.run
// which won't work. See also: https://discuss.gradle.org/t/4387/2
dependsOn { project(':minidns-integration-test').tasks.run }
}
task checkFull {
dependsOn = subprojects.tasks.check
dependsOn {
integrationTest
}
}
def getAndroidRuntimeJar(androidSdkApiLevel) {
def androidHome = getAndroidHome()
def androidJar = new File("$androidHome/platforms/android-$androidSdkApiLevel/android.jar")
if (androidJar.isFile()) {
return androidJar
} else {
throw new Exception("Can't find android.jar for $androidSdkApiLevel API. Please install corresponding SDK platform package")
}
}
def getAndroidHome() {
def androidHomeEnv = System.getenv("ANDROID_HOME")
if (androidHomeEnv == null) {
throw new Exception("ANDROID_HOME environment variable is not set")
}
def androidHome = new File(androidHomeEnv)
if (!androidHome.isDirectory()) throw new Exception("Environment variable ANDROID_HOME is not pointing to a directory")
return androidHome
}
def getGitCommit() {
def dotGit = new File("$projectDir/.git")
if (!dotGit.isDirectory()) return 'non-git build'
def cmd = 'git describe --always --tags --dirty=+'
def proc = cmd.execute()
def gitCommit = proc.text.trim()
assert !gitCommit.isEmpty()
def srCmd = 'git symbolic-ref --short HEAD'
def srProc = srCmd.execute()
srProc.waitForOrKill(10 * 1000)
if (srProc.exitValue() == 0) {
// Only add the information if the git command was
// successful. There may be no symbolic reference for HEAD if
// e.g. in detached mode.
def symbolicReference = srProc.text.trim()
assert !symbolicReference.isEmpty()
gitCommit += "-$symbolicReference"
}
gitCommit
}
task javadocAll(type: Javadoc) {
source subprojects.collect {project ->
project.sourceSets.main.allJava }
destinationDir = new File(buildDir, 'javadoc')
// Might need a classpath
classpath = files(subprojects.collect {project ->
project.sourceSets.main.compileClasspath})
options.linkSource = true
options.use = true
options.links = [
"https://docs.oracle.com/javase/${sourceCompatibility.getMajorVersion()}/docs/api/",
] as String[]
}