import java.text.SimpleDateFormat buildscript { repositories { maven { url "https://plugins.gradle.org/m2/" } mavenLocal() mavenCentral() } dependencies { classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2" } } plugins { id 'ru.vyarus.animalsniffer' version '1.5.0' } apply from: 'version.gradle' allprojects { apply plugin: 'java' apply plugin: 'idea' apply plugin: 'eclipse' apply plugin: 'jacoco' apply plugin: 'checkstyle' // animalsniffer apply plugin: 'ru.vyarus.animalsniffer' dependencies { signature "net.sf.androidscents.signature:android-api-level-${pgpainlessMinAndroidSdk}:2.3.1_r2@signature" } animalsniffer { sourceSets = [sourceSets.main] } // checkstyle checkstyle { toolVersion = '8.18' } group 'org.pgpainless' description = "Simple to use OpenPGP API for Java based on Bouncycastle" version = shortVersion sourceCompatibility = javaSourceCompatibility repositories { mavenCentral() } project.ext { junitVersion = 4.12 androidBootClasspath = getAndroidRuntimeJar(pgpainlessMinAndroidSdk) rootConfigDir = new File(rootDir, 'config') gitCommit = getGitCommit() builtDate = (new 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 (!project.ext.isSnapshot && !'git describe --exact-match HEAD'.execute().text.trim().equals(ext.shortVersion)) { throw new InvalidUserDataException('Untagged version detected! Please tag every release.') } if (!version.endsWith('-SNAPSHOT') && version != 'git tag --points-at HEAD'.execute().text.trim()) { throw new InvalidUserDataException( 'Tag mismatch detected, version is ' + version + ' but should be ' + 'git tag --points-at HEAD'.execute().text.trim()) } 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 } } } 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 'PGPainless' description 'Simple to use OpenPGP API for Java based on Bouncycastle' url 'https://github.com/pgpainless/pgpainless' inceptionYear '2018' scm { url 'https://github.com/pgpainless/pgpainless' connection 'scm:https://github.com/pgpainless/pgpainless' developerConnection 'scm:git://github.com/pgpainless/pgpainless.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 'vanitasvitae' name 'Paul Schaub' email 'vanitasvitae@fsfe.org' } } } } } } signing { required { signingRequired } sign configurations.archives } } 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 API level $androidSdkApiLevel at $androidHome/platforms/android-$androidSdkApiLevel/android.jar. 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 } apply plugin: "com.github.kt3k.coveralls" coveralls { sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath } task jacocoRootReport(type: 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 projectsWithUnitTests is wrong (e.g. a project is missing // in there). setOnlyIf { true } } 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[] }