build.gradle.kts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import java.io.ByteArrayOutputStream
  2. val baksmaliVersion by extra("3.0.3")
  3. val commonsCliVersion by extra("1.5.0")
  4. val commonsIoVersion by extra("2.13.0")
  5. val commonsLangVersion by extra("3.13.0")
  6. val commonsTextVersion by extra("1.10.0")
  7. val guavaVersion by extra("32.0.1-jre")
  8. val junitVersion by extra("4.13.2")
  9. val smaliVersion by extra("3.0.3")
  10. val xmlpullVersion by extra("1.1.4c")
  11. val xmlunitVersion by extra("2.9.1")
  12. val version = "2.8.2"
  13. val suffix = "6"
  14. // Strings embedded into the build.
  15. var gitRevision by extra("")
  16. var apktoolVersion by extra("")
  17. defaultTasks("build", "shadowJar", "proguard")
  18. // Functions
  19. val gitDescribe: String? by lazy {
  20. val stdout = ByteArrayOutputStream()
  21. try {
  22. rootProject.exec {
  23. commandLine("git", "describe", "--tags")
  24. standardOutput = stdout
  25. }
  26. stdout.toString().trim().replace("-g", "-")
  27. } catch (e: Exception) {
  28. null
  29. }
  30. }
  31. val gitBranch: String? by lazy {
  32. val stdout = ByteArrayOutputStream()
  33. try {
  34. rootProject.exec {
  35. commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
  36. standardOutput = stdout
  37. }
  38. stdout.toString().trim()
  39. } catch (e: Exception) {
  40. null
  41. }
  42. }
  43. if ("release" !in gradle.startParameter.taskNames) {
  44. val hash = this.gitDescribe
  45. if (hash == null) {
  46. gitRevision = "dirty"
  47. apktoolVersion = "$version-dirty"
  48. project.logger.lifecycle("Building SNAPSHOT (no .git folder found)")
  49. } else {
  50. gitRevision = hash
  51. apktoolVersion = "$hash-SNAPSHOT"
  52. project.logger.lifecycle("Building SNAPSHOT ($gitBranch): $gitRevision")
  53. }
  54. } else {
  55. gitRevision = ""
  56. apktoolVersion = if (suffix.isNotEmpty()) "$version-$suffix" else version;
  57. project.logger.lifecycle("Building RELEASE ($gitBranch): $apktoolVersion")
  58. }
  59. plugins {
  60. id("com.github.johnrengelman.shadow") version "8.1.1"
  61. `java-library`
  62. `maven-publish`
  63. signing
  64. }
  65. java {
  66. sourceCompatibility = JavaVersion.VERSION_1_8
  67. targetCompatibility = JavaVersion.VERSION_1_8
  68. }
  69. tasks.withType<JavaCompile> {
  70. options.compilerArgs.add("-Xlint:-options")
  71. options.compilerArgs.add("--release 8")
  72. options.encoding = "UTF-8"
  73. }
  74. allprojects {
  75. repositories {
  76. mavenCentral()
  77. google()
  78. }
  79. }
  80. subprojects {
  81. apply(plugin = "java")
  82. apply(plugin = "java-library")
  83. val mavenProjects = arrayOf("apktool-lib", "apktool-cli", "brut.j.common", "brut.j.util", "brut.j.dir")
  84. if (project.name in mavenProjects) {
  85. apply(plugin = "maven-publish")
  86. apply(plugin = "signing")
  87. java {
  88. withJavadocJar()
  89. withSourcesJar()
  90. }
  91. publishing {
  92. repositories {
  93. maven {
  94. url = uri("https://maven.pkg.github.com/revanced/Apktool")
  95. credentials {
  96. username = System.getenv("GITHUB_ACTOR") ?: project.findProperty("gpr.user").toString()
  97. password = System.getenv("GITHUB_TOKEN") ?: project.findProperty("gpr.key").toString()
  98. }
  99. }
  100. }
  101. publications {
  102. register("mavenJava", MavenPublication::class) {
  103. from(components["java"])
  104. groupId = "app.revanced"
  105. artifactId = project.name
  106. version = apktoolVersion
  107. pom {
  108. name = "Apktool"
  109. description = "A tool for reverse engineering Android apk files."
  110. url = "https://apktool.org"
  111. licenses {
  112. license {
  113. name = "The Apache License 2.0"
  114. url = "https://opensource.org/licenses/Apache-2.0"
  115. }
  116. }
  117. developers {
  118. developer {
  119. id = "iBotPeaches"
  120. name = "Connor Tumbleson"
  121. email = "connor.tumbleson@gmail.com"
  122. }
  123. developer {
  124. id = "brutall"
  125. name = "Ryszard Wiśniewski"
  126. email = "brut.alll@gmail.com"
  127. }
  128. }
  129. scm {
  130. connection = "scm:git:git://github.com/revanced/Apktool.git"
  131. developerConnection = "scm:git:git@github.com:revanced/Apktool.git"
  132. url = "https://github.com/revanced/Apktool"
  133. }
  134. }
  135. }
  136. }
  137. }
  138. tasks.withType<Javadoc>() {
  139. (options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
  140. }
  141. signing {
  142. useGpgCmd()
  143. sign(publishing.publications["mavenJava"])
  144. }
  145. }
  146. }
  147. // Used for official releases.
  148. task("release") {
  149. dependsOn("build")
  150. finalizedBy("publish")
  151. }