build.gradle.kts 4.7 KB

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