1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-23 19:38:00 +01:00
pgpainless/build.gradle

283 lines
9.2 KiB
Groovy
Raw Normal View History

2018-07-18 18:44:38 +02:00
import java.text.SimpleDateFormat
buildscript {
repositories {
2018-06-28 17:12:15 +02:00
maven {
url "https://plugins.gradle.org/m2/"
}
mavenLocal()
mavenCentral()
}
2018-07-24 16:23:24 +02:00
dependencies {
2020-01-09 19:03:06 +01:00
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2"
2018-07-24 16:23:24 +02:00
}
2018-06-02 21:21:35 +02:00
}
2018-07-18 18:44:38 +02:00
plugins {
2019-04-02 21:11:16 +02:00
id 'ru.vyarus.animalsniffer' version '1.5.0'
2018-07-18 18:44:38 +02:00
}
apply from: 'version.gradle'
2018-07-02 21:40:59 +02:00
allprojects {
2018-07-18 18:44:38 +02:00
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
2018-07-24 13:00:57 +02:00
apply plugin: 'jacoco'
2018-07-18 18:44:38 +02:00
apply plugin: 'checkstyle'
if (!it.name.equals('pgpainless-sop')) {
// animalsniffer
apply plugin: 'ru.vyarus.animalsniffer'
dependencies {
2021-02-03 12:42:15 +01:00
signature "net.sf.androidscents.signature:android-api-level-${pgpainlessMinAndroidSdk}:2.3.3_r2@signature"
}
animalsniffer {
sourceSets = [sourceSets.main]
}
2018-07-18 18:44:38 +02:00
}
// checkstyle
checkstyle {
2020-01-09 19:04:50 +01:00
toolVersion = '8.18'
2018-07-18 18:44:38 +02:00
}
2018-07-02 21:40:59 +02:00
group 'org.pgpainless'
description = "Simple to use OpenPGP API for Java based on Bouncycastle"
version = shortVersion
2018-06-02 21:21:35 +02:00
sourceCompatibility = javaSourceCompatibility
2018-06-02 21:21:35 +02:00
repositories {
mavenCentral()
}
2018-07-18 18:44:38 +02:00
2018-07-24 14:28:41 +02:00
project.ext {
2020-11-13 16:31:59 +01:00
junitVersion = '5.7.0'
2018-07-18 18:44:38 +02:00
androidBootClasspath = getAndroidRuntimeJar(pgpainlessMinAndroidSdk)
rootConfigDir = new File(rootDir, 'config')
gitCommit = getGitCommit()
builtDate = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date())
isContinuousIntegrationEnvironment = Boolean.parseBoolean(System.getenv('CI'))
2018-07-18 18:44:38 +02:00
isReleaseVersion = !isSnapshot
2020-04-14 15:21:13 +02:00
signingRequired = !(isSnapshot || isContinuousIntegrationEnvironment)
2018-07-18 18:44:38 +02:00
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'
}
def projectDirFile = new File("$projectDir")
if (!project.ext.isSnapshot && !'git describe --exact-match HEAD'.execute(null, projectDirFile).text.trim().equals(ext.shortVersion)) {
2018-07-18 18:44:38 +02:00
throw new InvalidUserDataException('Untagged version detected! Please tag every release.')
}
if (!version.endsWith('-SNAPSHOT') && version != 'git tag --points-at HEAD'.execute(null, projectDirFile).text.trim()) {
2018-07-18 18:44:38 +02:00
throw new InvalidUserDataException(
'Tag mismatch detected, version is ' + version + ' but should be ' +
'git tag --points-at HEAD'.execute(null, projectDirFile).text.trim())
2018-07-18 18:44:38 +02:00
}
2018-07-24 13:00:57 +02:00
jacoco {
2020-01-09 19:05:50 +01:00
toolVersion = "0.8.5"
2018-07-24 13:00:57 +02:00
}
jacocoTestReport {
dependsOn test
2020-01-09 19:05:50 +01:00
sourceDirectories.setFrom(project.files(sourceSets.main.allSource.srcDirs))
classDirectories.setFrom(project.files(sourceSets.main.output))
2018-07-24 13:00:57 +02:00
reports {
xml.enabled true
}
}
2020-11-13 16:31:59 +01:00
test {
useJUnitPlatform()
2021-04-26 13:38:12 +02:00
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
2020-11-13 16:31:59 +01:00
}
2018-06-02 21:21:35 +02:00
}
subprojects {
apply plugin: 'maven-publish'
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 testsJar(type: Jar, dependsOn: testClasses) {
classifier = 'tests'
from sourceSets.test.output
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
artifact testsJar
pom {
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'
}
}
}
}
}
repositories {
if (sonatypeCredentialsAvailable) {
maven {
url isSnapshot ? sonatypeSnapshotUrl : sonatypeStagingUrl
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
}
}
}
signing {
2020-04-14 15:21:13 +02:00
useGpgCmd()
required { signingRequired }
sign publishing.publications.mavenJava
}
def generatedVersionDir = "${buildDir}/generated-version"
sourceSets {
main {
output.dir(generatedVersionDir, builtBy: 'generateVersionProperties')
}
}
task generateVersionProperties {
doLast {
def propertiesFile = file "$generatedVersionDir/version.properties"
propertiesFile.parentFile.mkdirs()
def properties = new Properties()
properties.setProperty("version", rootProject.version.toString())
propertiesFile.withWriter { properties.store(it, null) }
}
}
processResources.dependsOn generateVersionProperties
2018-06-02 21:21:35 +02:00
}
2018-07-18 18:44:38 +02:00
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 projectDirFile = new File("$projectDir")
2018-07-18 18:44:38 +02:00
def dotGit = new File("$projectDir/.git")
if (!dotGit.isDirectory()) return 'non-git build'
def cmd = 'git describe --always --tags --dirty=+'
def proc = cmd.execute(null, projectDirFile)
2018-07-18 18:44:38 +02:00
def gitCommit = proc.text.trim()
assert !gitCommit.isEmpty()
def srCmd = 'git symbolic-ref --short HEAD'
def srProc = srCmd.execute(null, projectDirFile)
2018-07-18 18:44:38 +02:00
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
}
2018-07-24 16:23:24 +02:00
apply plugin: "com.github.kt3k.coveralls"
coveralls {
sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath
}
2018-07-24 17:31:21 +02:00
2018-07-24 13:00:57 +02:00
task jacocoRootReport(type: JacocoReport) {
2018-07-24 17:31:21 +02:00
dependsOn = subprojects.jacocoTestReport
2020-01-09 19:05:50 +01:00
sourceDirectories.setFrom(files(subprojects.sourceSets.main.allSource.srcDirs))
classDirectories.setFrom(files(subprojects.sourceSets.main.output))
executionData.setFrom(files(subprojects.jacocoTestReport.executionData))
2018-07-24 13:00:57 +02:00
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 }
}
2018-07-24 17:31:21 +02:00
2018-07-18 18:44:38 +02:00
task javadocAll(type: Javadoc) {
def currentJavaVersion = JavaVersion.current()
if (currentJavaVersion.compareTo(JavaVersion.VERSION_1_9) >= 0) {
options.addStringOption("-release", "8");
}
2018-07-18 18:44:38 +02:00
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[]
}