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