Free as in Freedom: Codeberg.org. Create your repos!
Simple to use OpenPGP API based on Bouncycastle https://pgpainless.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.gradle 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import java.text.SimpleDateFormat
  2. buildscript {
  3. repositories {
  4. maven {
  5. url "https://plugins.gradle.org/m2/"
  6. }
  7. mavenLocal()
  8. mavenCentral()
  9. }
  10. dependencies {
  11. classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1"
  12. }
  13. }
  14. plugins {
  15. id 'ru.vyarus.animalsniffer' version '1.5.0'
  16. }
  17. apply from: 'version.gradle'
  18. allprojects {
  19. apply plugin: 'java'
  20. apply plugin: 'idea'
  21. apply plugin: 'eclipse'
  22. apply plugin: 'jacoco'
  23. apply plugin: 'checkstyle'
  24. // animalsniffer
  25. apply plugin: 'ru.vyarus.animalsniffer'
  26. dependencies {
  27. signature "net.sf.androidscents.signature:android-api-level-${pgpainlessMinAndroidSdk}:2.3.1_r2@signature"
  28. }
  29. animalsniffer {
  30. sourceSets = [sourceSets.main]
  31. }
  32. // checkstyle
  33. checkstyle {
  34. configFile = "${project.rootDir}/config/checkstyle.xml" as File
  35. toolVersion = '8.10'
  36. }
  37. group 'org.pgpainless'
  38. description = "Simple to use OpenPGP API for Java based on Bouncycastle"
  39. version = shortVersion
  40. sourceCompatibility = javaSourceCompatibility
  41. repositories {
  42. mavenCentral()
  43. }
  44. project.ext {
  45. junitVersion = 4.12
  46. androidBootClasspath = getAndroidRuntimeJar(pgpainlessMinAndroidSdk)
  47. rootConfigDir = new File(rootDir, 'config')
  48. gitCommit = getGitCommit()
  49. builtDate = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date())
  50. isReleaseVersion = !isSnapshot
  51. signingRequired = isReleaseVersion
  52. sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')
  53. sonatypeSnapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
  54. sonatypeStagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
  55. }
  56. if (isSnapshot) {
  57. version = version + '-SNAPSHOT'
  58. }
  59. if (!project.ext.isSnapshot && !'git describe --exact-match HEAD'.execute().text.trim().equals(ext.shortVersion)) {
  60. throw new InvalidUserDataException('Untagged version detected! Please tag every release.')
  61. }
  62. if (!version.endsWith('-SNAPSHOT') && version != 'git tag --points-at HEAD'.execute().text.trim()) {
  63. throw new InvalidUserDataException(
  64. 'Tag mismatch detected, version is ' + version + ' but should be ' +
  65. 'git tag --points-at HEAD'.execute().text.trim())
  66. }
  67. jacoco {
  68. toolVersion = "0.8.1"
  69. }
  70. jacocoTestReport {
  71. dependsOn test
  72. sourceDirectories = project.files(sourceSets.main.allSource.srcDirs)
  73. classDirectories = project.files(sourceSets.main.output)
  74. reports {
  75. xml.enabled true
  76. }
  77. }
  78. }
  79. subprojects {
  80. apply plugin: 'maven'
  81. apply plugin: 'signing'
  82. task sourcesJar(type: Jar, dependsOn: classes) {
  83. classifier = 'sources'
  84. from sourceSets.main.allSource
  85. }
  86. task javadocJar(type: Jar, dependsOn: javadoc) {
  87. classifier = 'javadoc'
  88. from javadoc.destinationDir
  89. }
  90. task testJar(type: Jar, dependsOn: testClasses) {
  91. classifier = 'tests'
  92. from sourceSets.test.output
  93. }
  94. artifacts {
  95. archives sourcesJar
  96. archives javadocJar
  97. archives testJar
  98. }
  99. uploadArchives {
  100. repositories {
  101. mavenDeployer {
  102. if (signingRequired) {
  103. beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
  104. }
  105. repository(url: project.sonatypeStagingUrl) {
  106. if (sonatypeCredentialsAvailable) {
  107. authentication(userName: sonatypeUsername, password: sonatypePassword)
  108. }
  109. }
  110. snapshotRepository(url: project.sonatypeSnapshotUrl) {
  111. if (sonatypeCredentialsAvailable) {
  112. authentication(userName: sonatypeUsername, password: sonatypePassword)
  113. }
  114. }
  115. pom.project {
  116. name 'PGPainless'
  117. description 'Simple to use OpenPGP API for Java based on Bouncycastle'
  118. url 'https://github.com/pgpainless/pgpainless'
  119. inceptionYear '2018'
  120. scm {
  121. url 'https://github.com/pgpainless/pgpainless'
  122. connection 'scm:https://github.com/pgpainless/pgpainless'
  123. developerConnection 'scm:git://github.com/pgpainless/pgpainless.git'
  124. }
  125. licenses {
  126. license {
  127. name 'The Apache Software License, Version 2.0'
  128. url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  129. distribution 'repo'
  130. }
  131. }
  132. developers {
  133. developer {
  134. id 'vanitasvitae'
  135. name 'Paul Schaub'
  136. email 'vanitasvitae@fsfe.org'
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. signing {
  144. required { signingRequired }
  145. sign configurations.archives
  146. }
  147. }
  148. def getAndroidRuntimeJar(androidSdkApiLevel) {
  149. def androidHome = getAndroidHome()
  150. def androidJar = new File("$androidHome/platforms/android-$androidSdkApiLevel/android.jar")
  151. if (androidJar.isFile()) {
  152. return androidJar
  153. } else {
  154. 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")
  155. }
  156. }
  157. def getAndroidHome() {
  158. def androidHomeEnv = System.getenv("ANDROID_HOME")
  159. if (androidHomeEnv == null) {
  160. throw new Exception("ANDROID_HOME environment variable is not set")
  161. }
  162. def androidHome = new File(androidHomeEnv)
  163. if (!androidHome.isDirectory()) throw new Exception("Environment variable ANDROID_HOME is not pointing to a directory")
  164. return androidHome
  165. }
  166. def getGitCommit() {
  167. def dotGit = new File("$projectDir/.git")
  168. if (!dotGit.isDirectory()) return 'non-git build'
  169. def cmd = 'git describe --always --tags --dirty=+'
  170. def proc = cmd.execute()
  171. def gitCommit = proc.text.trim()
  172. assert !gitCommit.isEmpty()
  173. def srCmd = 'git symbolic-ref --short HEAD'
  174. def srProc = srCmd.execute()
  175. srProc.waitForOrKill(10 * 1000)
  176. if (srProc.exitValue() == 0) {
  177. // Only add the information if the git command was
  178. // successful. There may be no symbolic reference for HEAD if
  179. // e.g. in detached mode.
  180. def symbolicReference = srProc.text.trim()
  181. assert !symbolicReference.isEmpty()
  182. gitCommit += "-$symbolicReference"
  183. }
  184. gitCommit
  185. }
  186. apply plugin: "com.github.kt3k.coveralls"
  187. coveralls {
  188. sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath
  189. }
  190. task jacocoRootReport(type: JacocoReport) {
  191. dependsOn = subprojects.jacocoTestReport
  192. sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
  193. classDirectories = files(subprojects.sourceSets.main.output)
  194. executionData = files(subprojects.jacocoTestReport.executionData)
  195. reports {
  196. xml.enabled true
  197. xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
  198. }
  199. // We could remove the following setOnlyIf line, but then
  200. // jacocoRootReport would silently be SKIPPED if something with
  201. // the projectsWithUnitTests is wrong (e.g. a project is missing
  202. // in there).
  203. setOnlyIf { true }
  204. }
  205. task javadocAll(type: Javadoc) {
  206. source subprojects.collect {project ->
  207. project.sourceSets.main.allJava }
  208. destinationDir = new File(buildDir, 'javadoc')
  209. // Might need a classpath
  210. classpath = files(subprojects.collect {project ->
  211. project.sourceSets.main.compileClasspath})
  212. options.linkSource = true
  213. options.use = true
  214. options.links = [
  215. "https://docs.oracle.com/javase/${sourceCompatibility.getMajorVersion()}/docs/api/",
  216. ] as String[]
  217. }