Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
dependencies {
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2"
}
}
plugins {
id 'ru.vyarus.animalsniffer' version '1.5.0'
id 'net.ltgt.errorprone' version '0.8.1'
id 'me.champeau.gradle.jmh' version '0.4.8'
}
allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
repositories {
mavenLocal()
mavenCentral()
}
version readVersionFile()
ext {
isSnapshot = version.endsWith('-SNAPSHOT')
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
isContinuousIntegrationEnvironment = Boolean.parseBoolean(System.getenv('CI'))
signingRequired = !(isSnapshot || isContinuousIntegrationEnvironment)
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'
androidProjects = [':jxmpp-core', ':jxmpp-jid', ':jxmpp-stringprep-libidn', ':jxmpp-util-cache'].collect{ project(it) }
jmhProjects = [':jxmpp-util-cache'].collect { project(it) }
junit4Projects = [
':jxmpp-core',
':jxmpp-jid',
':jxmpp-repl',
':jxmpp-stringprep-icu4j',
':jxmpp-stringprep-libidn',
':jxmpp-util-cache',
].collect { project(it) }
// Only enable Error Prone for non JMH projects, as JMH
// uses generated Java source code which is prone to Error
// Prone bug patterns.
errorProneProjects = subprojects - project(":jxmpp-util-cache")
junitVersion = '5.6.1'
javaCompatilibity = JavaVersion.VERSION_1_8
javaMajor = javaCompatilibity.getMajorVersion()
jxmppMinAndroidSdk = 19
}
group = 'org.jxmpp'
sourceCompatibility = javaCompatilibity
targetCompatibility = sourceCompatibility
ext.sharedManifest = manifest {
attributes('Implementation-Version': version,
'Implementation-GitRevision': ext.gitCommit,
'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/target is set to 1.7 and
// bootclasspath is *not* set.
'-Xlint:-options',
'-Werror',
]
}
if (JavaVersion.current().isJava8Compatible()) {
tasks.withType(Javadoc) {
// The '-quiet' as second argument is actually a hack,
// since the one parameter 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')
}
}
if (JavaVersion.current().isJava9Compatible()) {
tasks.withType(Javadoc) {
options.addStringOption('-release', javaMajor)
}
tasks.withType(JavaCompile) {
options.compilerArgs.addAll([
'--release', javaMajor,
])
}
}
tasks.withType(Javadoc) {
options.charSet = "UTF-8"
}
jacoco {
toolVersion = "0.8.3"
}
jacocoTestReport {
dependsOn test
getSourceDirectories().setFrom(project.files(sourceSets.main.allSource.srcDirs))
getClassDirectories().setFrom(project.files(sourceSets.main.output))
reports {
xml.enabled true
}
}
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
}
test {
useJUnitPlatform()
// Enable full stacktraces of failed tests. Especially handy
// for environments like Travis.
testLogging {
events "failed"
exceptionFormat "full"
}
}
}
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/${javaMajor}/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-publish'
apply plugin: 'signing'
apply plugin: 'checkstyle'
checkstyle {
toolVersion = '8.22'
}
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 {
// See http://stackoverflow.com/a/21946676/194894
testRuntime testsJar
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
artifact testsJar
pom {
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'
}
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'
}
}
}
}
}
repositories {
maven {
url isSnapshot ? sonatypeSnapshotUrl : sonatypeStagingUrl
if (sonatypeCredentialsAvailable) {
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
}
}
}
rootProject.distributionZip {
dependsOn build
from(buildDir) {
include "$libsDirName/**"
}
}
// Workaround for gpg signatory not supporting the 'required' option
// See https://github.com/gradle/gradle/issues/5064#issuecomment-381924984
// Note what we use 'signing.gnupg.keyName' instead of 'signing.keyId'.
tasks.withType(Sign) {
onlyIf {
project.hasProperty('signing.gnupg.keyName')
}
}
signing {
required { signingRequired }
useGpgCmd()
sign publishing.publications.mavenJava
}
}
configure (errorProneProjects) {
apply plugin: 'net.ltgt.errorprone'
tasks.withType(JavaCompile) {
options.errorprone {
error(
"UnusedVariable",
"UnusedMethod",
"MethodCanBeStatic",
)
errorproneArgs = [
// Disable MissingCasesInEnumSwitch error prone check
// because this check is already done by javac as incomplete-switch.
'-Xep:MissingCasesInEnumSwitch:OFF',
'-Xep:StringSplitter:OFF',
'-Xep:JavaTimeDefaultTimeZone:OFF',
]
}
}
dependencies {
errorprone 'com.google.errorprone:error_prone_core:2.3.3'
errorproneJavac('com.google.errorprone:javac:9+181-r4173-1')
}
}
dependencies {
androidProjects.each { project ->
compile project
}
}
configure (junit4Projects) {
dependencies {
testImplementation "junit:junit:4.12"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$junitVersion"
}
}
configure (androidProjects) {
apply plugin: 'ru.vyarus.animalsniffer'
dependencies {
signature "net.sf.androidscents.signature:android-api-level-${jxmppMinAndroidSdk}:4.4.2_r4@signature"
}
animalsniffer {
sourceSets = [sourceSets.main]
}
}
configure (jmhProjects) {
apply plugin: "me.champeau.gradle.jmh"
// From https://github.com/melix/jmh-gradle-plugin/issues/35
// This should be theoretically not be needed with newer jmh
// gradle plugin versions. But without the following line "gradle
// eclipse" will add the jmh dependencies to the classpath
// TODO: This breaks with parboiled and is thus commented out.
// project.eclipse.classpath.plusConfigurations += [ configurations.jmh ]
jmh {
jmhVersion '1.21'
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
getSourceDirectories().setFrom(files(subprojects.sourceSets.main.allSource.srcDirs))
getClassDirectories().setFrom(files(subprojects.sourceSets.main.output))
getExecutionData().setFrom(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 projectDirFile = new File("$projectDir")
def dotGit = new File(projectDirFile, ".git")
if (!dotGit.isDirectory()) return 'non-git build'
def cmd = 'git describe --always --tags --dirty=+'
def proc = cmd.execute(null, projectDirFile)
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")
}
}
def readVersionFile() {
def versionFile = new File(rootDir, 'version')
if (!versionFile.isFile()) {
throw new Exception("Could not find version file")
}
if (versionFile.text.isEmpty()) {
throw new Exception("Version file does not contain a version")
}
versionFile.text.trim()
}