Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
365 lines (323 sloc) 9.92 KB
import org.gradle.plugins.signing.Sign
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
dependencies {
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2"
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.13'
}
}
plugins {
id 'ru.vyarus.animalsniffer' version '1.4.3'
id 'me.champeau.gradle.jmh' version '0.4.5'
}
apply from: 'version.gradle'
import net.ltgt.gradle.errorprone.ErrorProneToolChain
allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'net.ltgt.errorprone-base'
repositories {
mavenLocal()
mavenCentral()
}
ext {
gitCommit = getGitCommit()
javadocAllDir = new File(buildDir, 'javadoc')
documentationDir = new File(projectDir, 'documentation')
releasedocsDir = new File(buildDir, 'releasedocs')
rootConfigDir = new File(rootDir, 'config')
sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')
isReleaseVersion = !isSnapshot
signingRequired = isReleaseVersion
sonatypeSnapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
sonatypeStagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
builtDate = (new java.text.SimpleDateFormat("yyyy-MM-dd")).format(new Date())
oneLineDesc = 'An Open Source XMPP (Jabber) library'
jxmppMinAndroidSdk = 8
androidProjects = [':jxmpp-core', ':jxmpp-jid', ':jxmpp-stringprep-libidn', ':jxmpp-util-cache'].collect{ project(it) }
jmhProjects = [':jxmpp-util-cache'].collect { project(it) }
}
group = 'org.jxmpp'
sourceCompatibility = 1.7
targetCompatibility = sourceCompatibility
version = shortVersion
if (isSnapshot) {
version += '-SNAPSHOT'
}
ext.sharedManifest = manifest {
attributes('Implementation-Version': version,
'Implementation-GitRevision': ext.gitCommit,
// According to OSGi core 5.0 section 3.2.5 the qualifier (the fourth
// version element) must begin with a dot. So we replace only the
// first occurence of an dash with a dot.
// For example 4.0.0-rc1 becomes 4.0.0.rc1, but
// 4.0.0-SNAPSHOT-2014-05-01 becomes 4.0.0.SNAPSHOT-2014-05-01
'Bundle-Version': version.replaceFirst("-", "."),
'Built-Date': ext.builtDate,
'Built-JDK': System.getProperty('java.version'),
'Built-Gradle': gradle.gradleVersion,
'Built-By': System.getProperty('user.name')
)
}
eclipse {
classpath {
downloadJavadoc = true
}
}
// Make all project's 'test' target depend on javadoc, so that
// javadoc is also linted.
test.dependsOn javadoc
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.
'-Xlint:-options',
'-Werror',
]
if (!name.toLowerCase().contains('jmh')) {
// Only enable Error Prone for non JMH projects, as JMH
// uses generated Java source code which is prone to Error
// Prone bug patterns.
toolChain ErrorProneToolChain.create(project)
options.compilerArgs = [
// Disable MissingCasesInEnumSwitch error prone check
// because this check is already done by javac as incomplete-switch.
'-Xep:MissingCasesInEnumSwitch:OFF',
]
}
}
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.
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')
}
}
tasks.withType(Javadoc) {
options.charSet = "UTF-8"
}
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
}
}
dependencies {
errorprone 'com.google.errorprone:error_prone_core:2.2.0'
}
}
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()
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'
}
}
task javadocAll(type: Javadoc) {
source subprojects.collect {project ->
project.sourceSets.main.allJava }
destinationDir = javadocAllDir
// 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[]
}
task distributionZip(type: Zip, dependsOn: [javadocAll]) {
classifier builtDate
into ('javadoc') {
from(javadocAllDir)
}
}
jar {
// Root project should not create empty jar artifact
enabled = false
}
description = """\
JXMPP ${version}
${oneLineDesc}."""
// Disable uploadArchives task for the root project
uploadArchives.enabled = false
evaluationDependsOnChildren()
subprojects {
apply plugin: 'maven'
apply plugin: 'osgi'
apply plugin: 'signing'
apply plugin: 'checkstyle'
checkstyle {
configFile = new File(rootConfigDir, 'checkstyle.xml')
toolVersion = '8.8'
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
task testsJar(type: Jar) {
classifier = 'tests'
from sourceSets.test.output
}
artifacts {
archives sourcesJar
archives javadocJar
archives testsJar
}
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 'JXMPP'
packaging 'jar'
inceptionYear '2014'
url 'http://www.igniterealtime.org/projects/jxmpp/'
description project.description
issueManagement {
system 'JIRA'
url 'http://issues.igniterealtime.org/browse/JXMPP'
}
distributionManagement {
snapshotRepository {
id 'smack.snapshot'
url project.sonatypeSnapshotUrl
}
}
scm {
url 'https://github.com/igniterealtime/Smack'
connection 'scm:git:https://github.com/igniterealtime/Smack.git'
developerConnection 'scm:git:https://github.com/igniterealtime/Smack.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 'flow'
name 'Florian Schmaus'
email 'flow@igniterealtime.org'
}
}
}
}
}
}
rootProject.distributionZip {
dependsOn build
from(buildDir) {
include "$libsDirName/**"
}
}
signing {
required { signingRequired }
sign configurations.archives
}
}
dependencies {
androidProjects.each { project ->
compile project
}
}
configure (androidProjects) {
apply plugin: 'ru.vyarus.animalsniffer'
dependencies {
signature "net.sf.androidscents.signature:android-api-level-${jxmppMinAndroidSdk}:2.2_r3@signature"
}
animalsniffer {
sourceSets = [sourceSets.main]
}
}
configure (jmhProjects) {
apply plugin: "me.champeau.gradle.jmh"
jmh {
jmhVersion '1.20'
iterations 3
operationsPerInvocation 3
fork 3
}
}
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 }
}
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()
gitCommit
}
def getAndroidRuntimeJar() {
def androidHome = new File("$System.env.ANDROID_HOME")
if (!androidHome.isDirectory()) throw new Exception("ANDROID_HOME not found or set")
def androidJar = new File("$androidHome/platforms/android-$jxmppMinAndroidSdk/android.jar")
if (androidJar.isFile()) {
return androidJar
} else {
throw new Exception("Can't find android.jar for $jxmppMinAndroidSdk API. Please install corresponding SDK platform package")
}
}