From 342ff67a4cbc009e0a4954e4fc2fc3760344d014 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Sat, 5 Aug 2023 06:28:31 -0400 Subject: [PATCH] Migrate to Gradle Kotlin DSL (#3249) * feat: initial migration to kotlin * feat: initial migration to kotlin * fix: wire up dependencies * fix: Deprecated tag for kotlin detection * refactor: put all modules into sub-projects * fix: include jar file (android framework) * fix: add version message/info * fix: wire up version/gitrev to properties * fix: wire up proguard on cli * fix: wire up proguard * fix: wire up output cleaning command * fix: drop license header on gradle files - fully rewritten from scratch by myself - no longer including license header on build files * fix: add compile utf8/flags for java8 * refactor: remove unneeded curly braces * feat: progress towards maven-publish * build: publish to maven * docs: update documentation * refactor: prevent implicit order by removal of afterEvaluate * build: remove unused license plugin --- INTERNAL.md | 17 +- brut.apktool/apktool-cli/build.gradle | 100 -------- brut.apktool/apktool-cli/build.gradle.kts | 74 ++++++ .../src/main/java/brut/apktool/Main.java | 7 +- brut.apktool/apktool-lib/build.gradle | 50 ---- brut.apktool/apktool-lib/build.gradle.kts | 52 ++++ .../main/java/brut/androlib/apk/ApkInfo.java | 2 +- .../resources/properties/apktool.properties | 4 +- brut.j.common/build.gradle | 15 -- brut.j.common/build.gradle.kts | 0 brut.j.dir/build.gradle | 21 -- brut.j.dir/build.gradle.kts | 7 + brut.j.util/build.gradle | 21 -- brut.j.util/build.gradle.kts | 8 + build.gradle | 235 ------------------ build.gradle.kts | 186 ++++++++++++++ gradle/functions.gradle | 52 ---- settings.gradle | 6 - settings.gradle.kts | 2 + 19 files changed, 338 insertions(+), 521 deletions(-) delete mode 100644 brut.apktool/apktool-cli/build.gradle create mode 100644 brut.apktool/apktool-cli/build.gradle.kts delete mode 100644 brut.apktool/apktool-lib/build.gradle create mode 100644 brut.apktool/apktool-lib/build.gradle.kts delete mode 100644 brut.j.common/build.gradle create mode 100644 brut.j.common/build.gradle.kts delete mode 100644 brut.j.dir/build.gradle create mode 100644 brut.j.dir/build.gradle.kts delete mode 100644 brut.j.util/build.gradle create mode 100644 brut.j.util/build.gradle.kts delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 gradle/functions.gradle delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts diff --git a/INTERNAL.md b/INTERNAL.md index ff51dc7a..f8189920 100644 --- a/INTERNAL.md +++ b/INTERNAL.md @@ -4,17 +4,7 @@ The steps taken for slicing an official release of Apktool. ### Ensuring proper license headers -Before we build a release, its a good practice to ensure all headers in source files contain -proper licenses. - - ./gradlew licenseMain && ./gradlew licenseTest - -If any license violations were found you can automatically fix them with either - - ./gradlew licenseFormatMain - ./gradlew licenseFormatTest - -Like described, one formats the `src/main` directory, while the other formats the `src/test` directory. +_Currently broken after movement to kotlin dsl._ ### Tagging the release. @@ -56,12 +46,12 @@ ossrhUsername={sonatypeUsername} ossrhPassword={sonatypePassword} ``` -If `release` or `snapshot` is used publishing will be automatically attempted. +Release with maven with `./gradlew build shadowJar release publish`. ### Building the binary. In order to maintain a clean slate. Run `gradlew clean` to start from a clean slate. Now lets build -the new version. We should not have any new commits since the tagged commit. +the new binary version. We should not have any new commits since the tagged commit. ./gradlew build shadowJar proguard release @@ -151,7 +141,6 @@ except for containing sha256 hashes. The hashes match so we are good with the backup server. - #### Sonatype You'll want to log in and view the Staging repositories and confirm you see the recently made build. You'll want to: diff --git a/brut.apktool/apktool-cli/build.gradle b/brut.apktool/apktool-cli/build.gradle deleted file mode 100644 index 5d8a7dd3..00000000 --- a/brut.apktool/apktool-cli/build.gradle +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright 2014 Ryszard Wiśniewski - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import proguard.gradle.ProGuardTask - -buildscript { - dependencies { - repositories { - mavenCentral() - gradlePluginPortal() - } - - classpath(depends.proguard_gradle) { - exclude group: 'com.android.tools.build' - } - } -} - -plugins { - id 'com.github.johnrengelman.shadow' - id 'application' -} - -dependencies { - implementation depends.commons_cli - implementation project(':brut.apktool:apktool-lib') -} - -application { - mainClass = 'brut.apktool.Main' -} - -tasks.named('run') { - // run from root directory - // otherwise run from brut.apktool/apktool-cli - workingDir = file(System.getProperty('user.dir')) -} - -jar { - manifest { - attributes 'Main-Class': 'brut.apktool.Main' - } -} - -tasks.register('cleanOutputDirectory', Delete) { - delete fileTree(dir: jar.getDestinationDirectory().getAsFile(), exclude: "apktool-cli-all.jar") -} - -tasks.register('proguard', ProGuardTask) { - dependsOn shadowJar - injars shadowJar.getArchiveFile() - - // Java 9 and prior uses merged package for runtime, later uses split jmod files. - if (JavaVersion.current() <= JavaVersion.VERSION_1_8) { - libraryjars "${System.properties['java.home']}/lib/jce.jar" - libraryjars "${System.properties['java.home']}/lib/rt.jar" - } else { - libraryjars "${System.properties['java.home']}/jmods/java.base.jmod", jarfilter: '!**.jar', filter: '!module-info.class' - libraryjars "${System.properties['java.home']}/jmods/java.compiler.jmod", jarfilter: '!**.jar', filter: '!module-info.class' - libraryjars "${System.properties['java.home']}/jmods/java.logging.jmod", jarfilter: '!**.jar', filter: '!module-info.class' - libraryjars "${System.properties['java.home']}/jmods/java.xml.jmod", jarfilter: '!**.jar', filter: '!module-info.class' - libraryjars "${System.properties['java.home']}/jmods/java.desktop.jmod", jarfilter: '!**.jar', filter: '!module-info.class' - libraryjars "${System.properties['java.home']}/jmods/java.sql.jmod", jarfilter: '!**.jar', filter: '!module-info.class' - libraryjars "${System.properties['java.home']}/jmods/java.scripting.jmod", jarfilter: '!**.jar', filter: '!module-info.class' - - libraryjars "${System.properties['java.home']}/jmods/jdk.unsupported.jmod", jarfilter: '!**.jar', filter: '!module-info.class' - } - - dontobfuscate - dontoptimize - - keep 'public class brut.apktool.Main { public static void main(java.lang.String[]); }' - keepclassmembers 'enum * { public static **[] values(); public static ** valueOf(java.lang.String); }' - dontwarn 'com.google.common.base.**' - dontwarn 'com.google.common.collect.**' - dontwarn 'com.google.common.util.**' - dontwarn 'javax.xml.xpath.**' - dontnote '**' - // between Java 1.8 and 1.9, the signature of `flip()` changed, which trips up proguard. - - def outPath = jar.getDestinationDirectory().getAsFile().get().toString() - def extension = jar.archiveExtension.get().toString() - def outFile = outPath + '/' + "apktool" + '-' + project.apktool_version + '-small' + '.' + extension - outjars outFile -} - -proguard.dependsOn cleanOutputDirectory -tasks.getByPath(':release').dependsOn(proguard) diff --git a/brut.apktool/apktool-cli/build.gradle.kts b/brut.apktool/apktool-cli/build.gradle.kts new file mode 100644 index 00000000..2da6dd17 --- /dev/null +++ b/brut.apktool/apktool-cli/build.gradle.kts @@ -0,0 +1,74 @@ +import proguard.gradle.ProGuardTask + +val commonsCliVersion: String by rootProject.extra +val apktoolVersion: String by rootProject.extra + +plugins { + id("com.github.johnrengelman.shadow") + application +} + +// Buildscript is deprecated, but the alternative approach does not support expanded properties +// https://github.com/gradle/gradle/issues/9830 +// So we must hard-code the version here. +buildscript { + dependencies { + // Proguard doesn't support plugin DSL - https://github.com/Guardsquare/proguard/issues/225 + classpath("com.guardsquare:proguard-gradle:7.3.2") + } +} + +dependencies { + implementation("commons-cli:commons-cli:$commonsCliVersion") + implementation(project(":brut.apktool:apktool-lib")) +} + +application { + mainClass.set("brut.apktool.Main") + + tasks.run.get().workingDir = file(System.getProperty("user.dir")) +} + +tasks.withType { + manifest { + attributes["Main-Class"] = "brut.apktool.Main" + } +} + +tasks.register("cleanOutputDirectory") { + delete(fileTree("build/libs") { + exclude("apktool-cli-all.jar") + }) +} + +tasks.register("proguard") { + dependsOn("cleanOutputDirectory") + dependsOn("shadowJar") + injars(tasks.named("shadowJar").get().outputs.files) + + val javaHome = System.getProperty("java.home") + if (JavaVersion.current() <= JavaVersion.VERSION_1_8) { + libraryjars("$javaHome/lib/jce.jar") + libraryjars("$javaHome/lib/rt.jar") + } else { + libraryjars(mapOf("jarfilter" to "!**.jar", "filter" to "!module-info.class"), + { + "$javaHome/jmods/" + } + ) + } + + dontobfuscate() + dontoptimize() + + keep("class brut.apktool.Main { public static void main(java.lang.String[]); }") + keepclassmembers("enum * { public static **[] values(); public static ** valueOf(java.lang.String); }") + dontwarn("com.google.common.base.**") + dontwarn("com.google.common.collect.**") + dontwarn("com.google.common.util.**") + dontwarn("javax.xml.xpath.**") + dontnote("**") + + val outPath = "build/libs/apktool-cli-$apktoolVersion.jar" + outjars(outPath) +} diff --git a/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java b/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java index b67ae53d..396406aa 100644 --- a/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java +++ b/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java @@ -553,7 +553,7 @@ public class Main { // print out license info prior to formatter. System.out.println( - "Apktool v" + ApktoolProperties.getVersion() + " - a tool for reengineering Android apk files\n" + + "Apktool " + ApktoolProperties.getVersion() + " - a tool for reengineering Android apk files\n" + "with smali v" + ApktoolProperties.get("smaliVersion") + " and baksmali v" + ApktoolProperties.get("baksmaliVersion") + "\n" + "Copyright 2010 Ryszard Wiśniewski \n" + @@ -577,9 +577,8 @@ public class Main { System.out.println(); // print out more information - System.out.println( - "For additional info, see: https://apktool.org/ \n" - + "For smali/baksmali info, see: https://github.com/google/smali"); + System.out.println("For additional info, see: https://apktool.org \n" + + "For smali/baksmali info, see: https://github.com/google/smali"); } private static void setupLogging(final Verbosity verbosity) { diff --git a/brut.apktool/apktool-lib/build.gradle b/brut.apktool/apktool-lib/build.gradle deleted file mode 100644 index dcfa8ac5..00000000 --- a/brut.apktool/apktool-lib/build.gradle +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2014 Ryszard Wiśniewski - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import org.apache.tools.ant.filters.* - -apply plugin: 'java-library' - -processResources { - from('src/main/resources/properties') { - include '**/*.properties' - into 'properties' - filter(ReplaceTokens, tokens: [version: project.apktool_version, gitrev: project.hash] ) - duplicatesStrategy = DuplicatesStrategy.INCLUDE - } - from('src/main/resources/') { - include '**/*.jar' - duplicatesStrategy = DuplicatesStrategy.INCLUDE - } - - includeEmptyDirs = false -} - -dependencies { - api project(':brut.j.dir') - api project(':brut.j.util') - api project(':brut.j.common') - - implementation depends.baksmali - implementation depends.smali - implementation depends.xmlpull - implementation depends.guava - implementation depends.commons_lang - implementation depends.commons_io - implementation depends.commons_text - - testImplementation depends.junit - testImplementation depends.xmlunit -} diff --git a/brut.apktool/apktool-lib/build.gradle.kts b/brut.apktool/apktool-lib/build.gradle.kts new file mode 100644 index 00000000..9e7295b4 --- /dev/null +++ b/brut.apktool/apktool-lib/build.gradle.kts @@ -0,0 +1,52 @@ +val baksmaliVersion: String by rootProject.extra +val smaliVersion: String by rootProject.extra +val xmlpullVersion: String by rootProject.extra +val guavaVersion: String by rootProject.extra +val commonsLangVersion: String by rootProject.extra +val commonsIoVersion: String by rootProject.extra +val commonsTextVersion: String by rootProject.extra +val junitVersion: String by rootProject.extra +val xmlunitVersion: String by rootProject.extra + +val gitRevision: String by rootProject.extra +val apktoolVersion: String by rootProject.extra + +tasks { + processResources { + from("src/main/resources/properties") { + include("**/*.properties") + into("properties") + expand("version" to apktoolVersion, "gitrev" to gitRevision) + duplicatesStrategy = DuplicatesStrategy.INCLUDE + } + from("src/main/resources") { + include("**/*.jar") + duplicatesStrategy = DuplicatesStrategy.INCLUDE + } + includeEmptyDirs = false + } + + test { + // https://github.com/iBotPeaches/Apktool/issues/3174 - CVE-2023-22036 + // Increases validation of extra field of zip header. Some older Android applications + // used this field to store data violating the zip specification. + systemProperty("jdk.util.zip.disableZip64ExtraFieldValidation", true) + } +} + +dependencies { + api(project(":brut.j.dir")) + api(project(":brut.j.util")) + api(project(":brut.j.common")) + + implementation("com.android.tools.smali:smali-baksmali:$baksmaliVersion") + implementation("com.android.tools.smali:smali:$smaliVersion") + implementation("xpp3:xpp3:$xmlpullVersion") + implementation("com.google.guava:guava:$guavaVersion") + implementation("org.apache.commons:commons-lang3:$commonsLangVersion") + implementation("commons-io:commons-io:$commonsIoVersion") + implementation("org.apache.commons:commons-text:$commonsTextVersion") + + testImplementation("junit:junit:$junitVersion") + testImplementation("org.xmlunit:xmlunit-legacy:$xmlunitVersion") +} diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/apk/ApkInfo.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/apk/ApkInfo.java index 884b2a42..99faee09 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/apk/ApkInfo.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/apk/ApkInfo.java @@ -42,7 +42,7 @@ public class ApkInfo implements YamlSerializable { public Map unknownFiles = new LinkedHashMap<>(); public List doNotCompress; - /** @deprecated use {@link #resourcesAreCompressed} */ + /** @Deprecated use {@link #resourcesAreCompressed} */ public boolean compressionType; public ApkInfo() { diff --git a/brut.apktool/apktool-lib/src/main/resources/properties/apktool.properties b/brut.apktool/apktool-lib/src/main/resources/properties/apktool.properties index 36c063db..03cb9b37 100644 --- a/brut.apktool/apktool-lib/src/main/resources/properties/apktool.properties +++ b/brut.apktool/apktool-lib/src/main/resources/properties/apktool.properties @@ -1,2 +1,2 @@ -application.version=@version@ -git.commit.id.abbrev=@gitrev@ +application.version=${version} +git.commit.id.abbrev=${gitrev} diff --git a/brut.j.common/build.gradle b/brut.j.common/build.gradle deleted file mode 100644 index 41a98796..00000000 --- a/brut.j.common/build.gradle +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright 2014 Ryszard Wiśniewski - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ diff --git a/brut.j.common/build.gradle.kts b/brut.j.common/build.gradle.kts new file mode 100644 index 00000000..e69de29b diff --git a/brut.j.dir/build.gradle b/brut.j.dir/build.gradle deleted file mode 100644 index 0e5e1cfe..00000000 --- a/brut.j.dir/build.gradle +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2014 Ryszard Wiśniewski - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -dependencies { - implementation project(':brut.j.common') - implementation project(':brut.j.util') - implementation depends.commons_io -} diff --git a/brut.j.dir/build.gradle.kts b/brut.j.dir/build.gradle.kts new file mode 100644 index 00000000..2792b209 --- /dev/null +++ b/brut.j.dir/build.gradle.kts @@ -0,0 +1,7 @@ +val commonsIoVersion: String by rootProject.extra + +dependencies { + implementation(project(":brut.j.common")) + implementation(project(":brut.j.util")) + implementation("commons-io:commons-io:$commonsIoVersion") +} diff --git a/brut.j.util/build.gradle b/brut.j.util/build.gradle deleted file mode 100644 index b63c82b5..00000000 --- a/brut.j.util/build.gradle +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2014 Ryszard Wiśniewski - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -dependencies { - implementation project(':brut.j.common') - implementation depends.commons_io - implementation depends.guava -} diff --git a/brut.j.util/build.gradle.kts b/brut.j.util/build.gradle.kts new file mode 100644 index 00000000..b717cd3b --- /dev/null +++ b/brut.j.util/build.gradle.kts @@ -0,0 +1,8 @@ +val commonsIoVersion: String by rootProject.extra +val guavaVersion: String by rootProject.extra + +dependencies { + implementation(project(":brut.j.common")) + implementation("commons-io:commons-io:$commonsIoVersion") + implementation("com.google.guava:guava:$guavaVersion") +} diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 6cc5cb08..00000000 --- a/build.gradle +++ /dev/null @@ -1,235 +0,0 @@ -import java.nio.charset.StandardCharsets - -/** - * Copyright 2014 Ryszard Wiśniewski - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -buildscript { - ext { - depends = [ - baksmali : 'com.android.tools.smali:smali-baksmali:3.0.3', - commons_cli : 'commons-cli:commons-cli:1.5.0', - commons_io : 'commons-io:commons-io:2.13.0', - commons_lang : 'org.apache.commons:commons-lang3:3.13.0', - commons_text : 'org.apache.commons:commons-text:1.10.0', - guava : 'com.google.guava:guava:32.0.1-jre', - junit : 'junit:junit:4.13.2', - proguard_gradle: 'com.guardsquare:proguard-gradle:7.3.2', - smali : 'com.android.tools.smali:smali:3.0.3', - xmlpull : 'xpp3:xpp3:1.1.4c', - xmlunit : 'org.xmlunit:xmlunit-legacy:2.9.1', - ] - } - - repositories { - gradlePluginPortal() - google() - } - dependencies { - classpath "gradle.plugin.com.github.johnrengelman:shadow:8.0.0" - classpath "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.16.1" - } -} - -apply from: 'gradle/functions.gradle' - -version = '2.8.2' -def suffix = 'SNAPSHOT' - -defaultTasks 'build', 'shadowJar', 'proguard' - -allprojects { - apply plugin: 'java' - apply plugin: 'com.github.hierynomus.license' - - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - - license { - header rootProject.file("brut.j.common/src/templates/apache2.0-header.txt") - exclude "**/android/content/res/*.java" - exclude "**/android/util/*.java" - include "**/*.java" - mapping { - java = 'SLASHSTAR_STYLE' - } - ext { - year = '2010' - brut = 'Ryszard Wiśniewski' - brutEmail = 'brut.alll@gmail.com' - ibot = 'Connor Tumbleson' - ibotEmail = 'connor.tumbleson@gmail.com' - } - strictCheck true - } - - // license plugin automatically fires these tasks, disable them and run them during releases - gradle.startParameter.excludedTaskNames += [ - "licenseMain", - "licenseTest" - ] - - repositories { - mavenCentral() - google() - } -} - -tasks.withType(JavaCompile).configureEach { - options.encoding = StandardCharsets.UTF_8.toString() - options.compilerArgs += ["-Xlint:-options"] -} - -def mavenVersion = 'unspecified' -if (!('release' in gradle.startParameter.taskNames)) { - def hash = getCheckedOutGitCommitHash() - - if (hash == null) { - project.ext.set("hash", "dirty") - project.ext.set("apktool_version", version + "-dirty") - println "Building SNAPSHOT (no .git folder found)" - } else { - project.ext.set("hash", hash) - project.ext.set("apktool_version", version + "-" + hash + "-SNAPSHOT") - mavenVersion = version + "-SNAPSHOT" - println "Building SNAPSHOT (${getCheckedOutBranch()}): $hash" - } -} else { - project.ext.set("hash", "") - if (suffix.length() > 0) { - project.ext.set("apktool_version", version + "-" + suffix) - } else { - project.ext.set("apktool_version", version) - } - mavenVersion = version - println "Building RELEASE (${getCheckedOutBranch()}): $project.ext.apktool_version" -} - -build.doFirst { - def javaVersion = System.getProperty("java.version") - - // fail the build if java (1.5/1.6/1.7) - if (javaVersion.startsWith("1.5") || javaVersion.startsWith("1.6") || javaVersion.startsWith("1.7")) { - throw new GradleException("You can fix this problem!\n" + - "We found a " + javaVersion + " JDK\n" + - "Please update JAVA_HOME to use at least a 1.8 JDK\n" + - "Currently it is set to: " + System.getProperty("java.home") - ) - } -} - -// used for official releases only. Please don't use -task release { -} - -// used for publishing snapshot builds to maven. -task snapshot { -} - -subprojects { - apply plugin: 'java' - - test { - // https://github.com/iBotPeaches/Apktool/issues/3174 - systemProperty 'jdk.nio.zipfs.allowDotZipEntry', 'true' - systemProperty 'jdk.util.zip.disableZip64ExtraFieldValidation', 'true' - - testLogging { - exceptionFormat = 'full' - } - } - - def mavenProjects = ['apktool-lib', 'apktool-cli', 'brut.j.common', 'brut.j.util', 'brut.j.dir'] - - if (project.name in mavenProjects) { - apply plugin: 'maven-publish' - apply plugin: 'signing' - - publishing { - publications { - maven(MavenPublication) { - from project.components.java - - groupId = 'org.apktool' - artifactId = project.name - version = mavenVersion - - pom { - name = 'Apktool' - description = 'A tool for reverse engineering Android apk files.' - url = 'https://apktool.org' - - licenses { - license { - name = 'The Apache License 2.0' - url = 'https://opensource.org/licenses/Apache-2.0' - } - } - developers { - developer { - id = 'iBotPeaches' - name = 'Connor Tumbleson' - email = 'connor.tumbleson@gmail.com' - } - developer { - id = 'brutall' - name = 'Ryszard Wiśniewski' - email = 'brut.alll@gmail.com' - } - } - scm { - connection = 'scm:git:git://github.com/iBotPeaches/Apktool.git' - developerConnection = 'scm:git:git@github.com:iBotPeaches/Apktool.git' - url = 'https://github.com/iBotPeaches/Apktool' - } - } - } - } - if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) { - repositories { - maven { - if (mavenVersion.endsWith('-SNAPSHOT')) { - url = 'https://s01.oss.sonatype.org/content/repositories/snapshots/' - } else { - url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/' - } - credentials { - username ossrhUsername - password ossrhPassword - } - } - } - } - } - - signing { - required { gradle.taskGraph.hasTask('publish') } - sign(publishing.publications["maven"]) - } - - java { - withJavadocJar() - withSourcesJar() - } - - tasks.getByPath(':release').dependsOn(publish) - tasks.getByPath(':snapshot').dependsOn(publish) - - tasks.withType(Javadoc).tap { - configureEach { - options.addStringOption('Xdoclint:none', '-quiet') - } - } - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..ed6c458e --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,186 @@ +import java.io.ByteArrayOutputStream + +val baksmaliVersion by extra("3.0.3") +val commonsCliVersion by extra("1.5.0") +val commonsIoVersion by extra("2.13.0") +val commonsLangVersion by extra("3.13.0") +val commonsTextVersion by extra("1.10.0") +val guavaVersion by extra("32.0.1-jre") +val junitVersion by extra("4.13.2") +val smaliVersion by extra("3.0.3") +val xmlpullVersion by extra("1.1.4c") +val xmlunitVersion by extra("2.9.1") + +val version = "2.8.2" +val suffix = "SNAPSHOT" + +// Strings embedded into the build. +var gitRevision by extra("") +var apktoolVersion by extra("") + +defaultTasks("build", "shadowJar", "proguard") + +// Functions +val gitDescribe: String? by lazy { + val stdout = ByteArrayOutputStream() + try { + rootProject.exec { + commandLine("git", "describe", "--tags") + standardOutput = stdout + } + stdout.toString().trim().replace("-g", "-") + } catch (e: Exception) { + null + } +} + +val gitBranch: String? by lazy { + val stdout = ByteArrayOutputStream() + try { + rootProject.exec { + commandLine("git", "rev-parse", "--abbrev-ref", "HEAD") + standardOutput = stdout + } + stdout.toString().trim() + } catch (e: Exception) { + null + } +} + +if ("release" !in gradle.startParameter.taskNames) { + val hash = this.gitDescribe + + if (hash == null) { + gitRevision = "dirty" + apktoolVersion = "$version-dirty" + project.logger.lifecycle("Building SNAPSHOT (no .git folder found)") + } else { + gitRevision = hash + apktoolVersion = "$hash-SNAPSHOT" + project.logger.lifecycle("Building SNAPSHOT ($gitBranch): $gitRevision") + } +} else { + gitRevision = "" + apktoolVersion = if (suffix.isNotEmpty()) "$version-$suffix" else version; + project.logger.lifecycle("Building RELEASE ($gitBranch): $apktoolVersion") +} + +plugins { + `java-library` + `maven-publish` + signing +} + +buildscript { + repositories { + gradlePluginPortal() + google() + } + dependencies { + classpath("gradle.plugin.com.github.johnrengelman:shadow:8.0.0") + } +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +tasks.withType { + options.compilerArgs.add("-Xlint:-options") + options.compilerArgs.add("--release 8") + + options.encoding = "UTF-8" +} + +allprojects { + repositories { + mavenCentral() + google() + } +} + +subprojects { + apply(plugin = "java") + apply(plugin = "java-library") + + val mavenProjects = arrayOf("apktool-lib", "apktool-cli", "brut.j.common", "brut.j.util", "brut.j.dir") + + if (project.name in mavenProjects) { + apply(plugin = "maven-publish") + apply(plugin = "signing") + + java { + withJavadocJar() + withSourcesJar() + } + + publishing { + repositories { + maven { + url = if (suffix.contains("SNAPSHOT")) { + uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") + } else { + uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") + } + credentials { + username = (project.properties["ossrhUsername"] ?: "").toString() + password = (project.properties["ossrhPassword"] ?: "").toString() + } + } + } + publications { + register("mavenJava", MavenPublication::class) { + from(components["java"]) + groupId = "org.apktool" + artifactId = project.name + version = apktoolVersion + + pom { + name = "Apktool" + description = "A tool for reverse engineering Android apk files." + url = "https://apktool.org" + + licenses { + license { + name = "The Apache License 2.0" + url = "https://opensource.org/licenses/Apache-2.0" + } + } + developers { + developer { + id = "iBotPeaches" + name = "Connor Tumbleson" + email = "connor.tumbleson@gmail.com" + } + developer { + id = "brutall" + name = "Ryszard Wiśniewski" + email = "brut.alll@gmail.com" + } + } + scm { + connection = "scm:git:git://github.com/iBotPeaches/Apktool.git" + developerConnection = "scm:git:git@github.com:iBotPeaches/Apktool.git" + url = "https://github.com/iBotPeaches/Apktool" + } + } + } + } + } + + tasks.withType() { + (options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet") + } + + signing { + sign(publishing.publications["mavenJava"]) + } + } +} + +// Used for official releases. +task("release") { + dependsOn("build") + finalizedBy("publish") +} diff --git a/gradle/functions.gradle b/gradle/functions.gradle deleted file mode 100644 index f178be7d..00000000 --- a/gradle/functions.gradle +++ /dev/null @@ -1,52 +0,0 @@ -import org.codehaus.groovy.runtime.MethodClosure - -/** - * Copyright 2014 Ryszard Wiśniewski - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -def getCheckedOutGitCommitHash() { - def gitFolder = "$projectDir/.git/" - def takeFromHash = 6 - - def head - try { - head = new File(gitFolder + "HEAD").text.split(":") - } catch(Exception ignored) { - return null - } - - def isCommit = head.length == 1 - if(isCommit) return head[0].trim().take(takeFromHash) - - def refHead = new File(gitFolder + head[1].trim()) - refHead.text.trim().take takeFromHash -} - -def getCheckedOutBranch() { - def gitFolder = "$projectDir/.git/" - - def head - try { - head = new File(gitFolder + "HEAD").text.split("/") - return head[2].trim() - } catch(Exception ignored) { - return "SNAPSHOT" - } -} - -ext { - getCheckedOutGitCommitHash = this.&getCheckedOutGitCommitHash as MethodClosure - getCheckedOutBranch = this.&getCheckedOutBranch as MethodClosure -} diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 903ece38..00000000 --- a/settings.gradle +++ /dev/null @@ -1,6 +0,0 @@ -rootProject.name = 'apktool-cli' -include 'brut.j.common', - 'brut.j.util', - 'brut.j.dir', - 'brut.apktool:apktool-lib', - 'brut.apktool:apktool-cli' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..9fffe0ae --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "apktool-cli" +include("brut.j.common", "brut.j.util", "brut.j.dir", "brut.apktool:apktool-lib", "brut.apktool:apktool-cli")