From bed2f2e5d61ab8a4d3c0e4dabe6d60ffc3d1c1ec Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 3 May 2023 00:43:18 +0530 Subject: [PATCH] gradle: convert build files to Kotlin Signed-off-by: Harsh Shandilya --- build.gradle | 33 ---------- build.gradle.kts | 13 ++++ gradle.properties | 3 + gradle/libs.versions.toml | 29 +++++++++ settings.gradle | 28 --------- settings.gradle.kts | 22 +++++++ tunnel/build.gradle | 72 --------------------- tunnel/build.gradle.kts | 129 ++++++++++++++++++++++++++++++++++++++ tunnel/publish.gradle | 82 ------------------------ ui/build.gradle | 81 ------------------------ ui/build.gradle.kts | 82 ++++++++++++++++++++++++ version.gradle | 6 -- 12 files changed, 278 insertions(+), 302 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 gradle/libs.versions.toml delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts delete mode 100644 tunnel/build.gradle create mode 100644 tunnel/build.gradle.kts delete mode 100644 tunnel/publish.gradle delete mode 100644 ui/build.gradle create mode 100644 ui/build.gradle.kts delete mode 100644 version.gradle diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 35e5dadd..00000000 --- a/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -buildscript { - ext { - activityVersion = '1.7.1' - annotationsVersion = '1.6.0' - appcompatVersion = '1.6.1' - biometricVersion = '1.1.0' - collectionVersion = '1.2.0' - constraintLayoutVersion = '2.1.4' - coordinatorLayoutVersion = '1.2.0' - coreKtxVersion = '1.10.0' - coroutinesVersion = '1.6.4' - datastoreVersion = '1.0.0' - desugarVersion = '1.1.5' - fragmentVersion = '1.5.7' - jsr305Version = '3.0.2' - junitVersion = '4.13.2' - lifecycleRuntimeKtxVersion = '2.6.1' - materialComponentsVersion = '1.8.0' - preferenceVersion = '1.2.0' - zxingEmbeddedVersion = '4.3.0' - - groupName = 'com.wireguard.android' - } -} - -tasks { - wrapper { - gradleVersion = "8.1.1" - distributionSha256Sum = "e111cb9948407e26351227dabce49822fb88c37ee72f1d1582a69c68af2e702f" - } -} - -apply from: "version.gradle" diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..acd4e797 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + alias(libs.plugins.android.application) apply false + alias(libs.plugins.android.library) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.kotlin.kapt) apply false +} + +tasks { + wrapper { + gradleVersion = "8.1.1" + distributionSha256Sum = "e111cb9948407e26351227dabce49822fb88c37ee72f1d1582a69c68af2e702f" + } +} diff --git a/gradle.properties b/gradle.properties index db5593b3..d300054d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -63,6 +63,9 @@ android.suppressUnsupportedOptionWarnings=android.keepWorkerActionServicesBetwee android.enableAppCompileTimeRClass,\ android.suppressUnsupportedOptionWarnings +wireguardVersionCode=501 +wireguardVersionName=1.0.20230502 + # OSSRH sometimes struggles with slow deployments, so this makes Gradle # more tolerant to those delays. systemProp.org.gradle.internal.http.connectionTimeout=500000 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..87e8efc4 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,29 @@ +[versions] +agp = "8.0.0" +kotlin = "1.8.0" + +[libraries] +androidx-activity-ktx = "androidx.activity:activity-ktx:1.7.1" +androidx-annotation = "androidx.annotation:annotation:1.6.0" +androidx-appcompat = "androidx.appcompat:appcompat:1.6.1" +androidx-biometric = "androidx.biometric:biometric:1.1.0" +androidx-collection = "androidx.collection:collection:1.2.0" +androidx-constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.4" +androidx-coordinatorlayout = "androidx.coordinatorlayout:coordinatorlayout:1.2.0" +androidx-core-ktx = "androidx.core:core-ktx:1.10.0" +androidx-datastore-preferences = "androidx.datastore:datastore-preferences:1.0.0" +androidx-fragment-ktx = "androidx.fragment:fragment-ktx:1.5.7" +androidx-lifecycle-runtime-ktx = "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1" +androidx-preference-ktx = "androidx.preference:preference-ktx:1.2.0" +desugarJdkLibs = "com.android.tools:desugar_jdk_libs:1.1.5" +google-material = "com.google.android.material:material:1.8.0" +jsr305 = "com.google.code.findbugs:jsr305:3.0.2" +junit = "junit:junit:4.13.2" +kotlinx-coroutines-android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4" +zxing-android-embedded = "com.journeyapps:zxing-android-embedded:4.3.0" + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +android-library = { id = "com.android.library", version.ref = "agp" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 996d8afd..00000000 --- a/settings.gradle +++ /dev/null @@ -1,28 +0,0 @@ -pluginManagement { - def agpVersion = '8.0.0' - def kotlinVersion = "1.8.0" - repositories { - gradlePluginPortal() - google() - mavenCentral() - } - plugins { - id("com.android.application") version "$agpVersion" - id("com.android.library") version "$agpVersion" - id("org.jetbrains.kotlin.android") version "$kotlinVersion" - id("org.jetbrains.kotlin.kapt") version "$kotlinVersion" - } -} - -dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) - repositories { - google() - mavenCentral() - } -} - -rootProject.name = "wireguard-android" - -include ':tunnel' -include ':ui' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..91bc0b90 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,22 @@ +@file:Suppress("UnstableApiUsage") + +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "wireguard-android" + +include(":tunnel") +include(":ui") diff --git a/tunnel/build.gradle b/tunnel/build.gradle deleted file mode 100644 index 894762c9..00000000 --- a/tunnel/build.gradle +++ /dev/null @@ -1,72 +0,0 @@ -plugins { - id 'com.android.library' -} - -version wireguardVersionName -group groupName - -android { - compileSdk 33 - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - namespace 'com.wireguard.android.tunnel' - defaultConfig { - minSdkVersion 21 - targetSdkVersion 33 - versionCode wireguardVersionCode - versionName wireguardVersionName - } - externalNativeBuild { - cmake { - path 'tools/CMakeLists.txt' - } - } - testOptions.unitTests.all { - testLogging { - events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' - } - } - buildTypes { - all { - externalNativeBuild { - cmake { - targets 'libwg-go.so', 'libwg.so', 'libwg-quick.so' - arguments "-DGRADLE_USER_HOME=${project.gradle.gradleUserHomeDir}" - } - } - } - release { - externalNativeBuild { - cmake { - arguments "-DANDROID_PACKAGE_NAME=${groupName}" - } - } - } - debug { - externalNativeBuild { - cmake { - arguments "-DANDROID_PACKAGE_NAME=${groupName}.debug" - } - } - } - } - lint { - disable 'LongLogTag', 'NewApi' - } - publishing { - multipleVariants("release") { - allVariants() - } - } -} - -dependencies { - implementation "androidx.annotation:annotation:$annotationsVersion" - implementation "androidx.collection:collection:$collectionVersion" - compileOnly "com.google.code.findbugs:jsr305:$jsr305Version" - testImplementation "junit:junit:$junitVersion" -} - -apply from: "publish.gradle" diff --git a/tunnel/build.gradle.kts b/tunnel/build.gradle.kts new file mode 100644 index 00000000..1039923a --- /dev/null +++ b/tunnel/build.gradle.kts @@ -0,0 +1,129 @@ +@file:Suppress("UnstableApiUsage") +import org.gradle.api.tasks.testing.logging.TestLogEvent + +plugins { + alias(libs.plugins.android.library) + `maven-publish` + signing +} + +android { + compileSdk = 33 + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + namespace = "com.wireguard.android.tunnel" + defaultConfig { + minSdk = 21 + } + externalNativeBuild { + cmake { + path("tools/CMakeLists.txt") + } + } + testOptions.unitTests.all { + it.testLogging { events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) } + } + buildTypes { + all { + externalNativeBuild { + cmake { + targets("libwg-go.so", "libwg.so", "libwg-quick.so") + arguments("-DGRADLE_USER_HOME=${project.gradle.gradleUserHomeDir}") + } + } + } + release { + externalNativeBuild { + cmake { + arguments("-DANDROID_PACKAGE_NAME=com.wireguard.android") + } + } + } + debug { + externalNativeBuild { + cmake { + arguments("-DANDROID_PACKAGE_NAME=com.wireguard.android.debug") + } + } + } + } + lint { + disable.add("LongLogTag") + disable.add("NewApi") + } + publishing { + singleVariant("release") { + withJavadocJar() + withSourcesJar() + } + } +} + +dependencies { + implementation(libs.androidx.annotation) + implementation(libs.androidx.collection) + compileOnly(libs.jsr305) + testImplementation(libs.junit) +} + +publishing { + publications { + register("release") { + groupId = "com.wireguard.android" + artifactId = "tunnel" + version = providers.gradleProperty("wireguardVersionName").get() + afterEvaluate { + from(components["release"]) + } + pom { + name.set("WireGuard Tunnel Library") + description.set("Embeddable tunnel library for WireGuard for Android") + url.set("https://www.wireguard.com/") + + licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") + } + } + scm { + connection.set("scm:git:https://git.zx2c4.com/wireguard-android") + developerConnection.set("scm:git:https://git.zx2c4.com/wireguard-android") + url.set("https://git.zx2c4.com/wireguard-android") + } + developers { + organization { + name.set("WireGuard") + url.set("https://www.wireguard.com/") + } + developer { + name.set("WireGuard") + email.set("team@wireguard.com") + } + } + } + } + } + repositories { + maven { + name = "sonatype" + url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + credentials { + username = providers.gradleProperty("SONATYPE_USER") + .orElse(providers.environmentVariable("SONATYPE_USER")) + .orNull + password = providers.gradleProperty("SONATYPE_PASSWORD") + .orElse(providers.environmentVariable("SONATYPE_PASSWORD")) + .orNull + } + } + } +} + +signing { + useGpgCmd() + sign(publishing.publications) +} diff --git a/tunnel/publish.gradle b/tunnel/publish.gradle deleted file mode 100644 index fd4ef18b..00000000 --- a/tunnel/publish.gradle +++ /dev/null @@ -1,82 +0,0 @@ -apply plugin: 'maven-publish' -apply plugin: 'signing' - -afterEvaluate { - publishing { - publications { - release(MavenPublication) { - groupId = groupName - artifactId = 'tunnel' - version wireguardVersionName - - artifact sourcesJar - artifact javadocJar - - from components.getByName("release") - - pom { - name = 'WireGuard Tunnel Library' - description = 'Embeddable tunnel library for WireGuard for Android' - url = 'https://www.wireguard.com/' - - licenses { - license { - name = 'The Apache Software License, Version 2.0' - url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution = 'repo' - } - } - scm { - connection = 'scm:git:https://git.zx2c4.com/wireguard-android' - developerConnection = 'scm:git:https://git.zx2c4.com/wireguard-android' - url = 'https://git.zx2c4.com/wireguard-android' - } - developers { - organization { - name = 'WireGuard' - url = 'https://www.wireguard.com/' - } - developer { - name = 'WireGuard' - email = 'team@wireguard.com' - } - } - } - } - } - repositories { - maven { - name = "sonatype" - url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") - credentials { - username = hasProperty('SONATYPE_USER') ? getProperty('SONATYPE_USER') : System.getenv('SONATYPE_USER') - password = hasProperty('SONATYPE_PASSWORD') ? getProperty('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD') - } - } - } - } -} - -android.libraryVariants.all { variant -> - if (variant.name == 'release') { - task javadoc(type: Javadoc) { - source = variant.javaCompileProvider.get().source - classpath = files((android.bootClasspath.join(File.pathSeparator))) - classpath += variant.javaCompileProvider.get().classpath - title = 'Embeddable WireGuard Tunnel for Android v$wireguardVersionName' - } - task javadocJar(type: Jar, dependsOn: javadoc) { - archiveClassifier = 'javadoc' - from javadoc.destinationDir - } - task sourcesJar(type: Jar) { - archiveClassifier = 'sources' - from android.sourceSets.main.java.srcDirs - } - } -} - -signing { - useGpgCmd() - sign publishing.publications -} diff --git a/ui/build.gradle b/ui/build.gradle deleted file mode 100644 index dd2abe8d..00000000 --- a/ui/build.gradle +++ /dev/null @@ -1,81 +0,0 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -plugins { - id 'com.android.application' - id 'org.jetbrains.kotlin.android' - id 'org.jetbrains.kotlin.kapt' -} - -version wireguardVersionName -group groupName - -android { - compileSdk 33 - buildFeatures { - buildConfig = true - dataBinding = true - viewBinding = true - } - namespace = 'com.wireguard.android' - defaultConfig { - applicationId 'com.wireguard.android' - minSdkVersion 21 - targetSdkVersion 33 - versionCode wireguardVersionCode - versionName wireguardVersionName - buildConfigField 'int', 'MIN_SDK_VERSION', "$minSdkVersion.apiLevel" - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - coreLibraryDesugaringEnabled = true - } - buildTypes { - release { - minifyEnabled true - shrinkResources true - proguardFiles "proguard-android-optimize.txt" - packagingOptions { - exclude "DebugProbesKt.bin" - exclude "kotlin-tooling-metadata.json" - } - } - debug { - applicationIdSuffix ".debug" - versionNameSuffix "-debug" - } - } - lint { - disable 'LongLogTag' - warning 'MissingTranslation', 'ImpliedQuantity' - } -} - -dependencies { - implementation project(":tunnel") - implementation "androidx.activity:activity-ktx:$activityVersion" - implementation "androidx.annotation:annotation:$annotationsVersion" - implementation "androidx.appcompat:appcompat:$appcompatVersion" - implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion" - implementation "androidx.coordinatorlayout:coordinatorlayout:$coordinatorLayoutVersion" - implementation "androidx.biometric:biometric:$biometricVersion" - implementation "androidx.core:core-ktx:$coreKtxVersion" - implementation "androidx.fragment:fragment-ktx:$fragmentVersion" - implementation "androidx.preference:preference-ktx:$preferenceVersion" - implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleRuntimeKtxVersion" - implementation "androidx.datastore:datastore-preferences:$datastoreVersion" - implementation "com.google.android.material:material:$materialComponentsVersion" - implementation "com.journeyapps:zxing-android-embedded:$zxingEmbeddedVersion" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" - coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$desugarVersion" -} - -tasks.withType(JavaCompile).configureEach { - options.compilerArgs << '-Xlint:unchecked' - options.deprecation = true -} - -tasks.withType(KotlinCompile).configureEach { - kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8 -} diff --git a/ui/build.gradle.kts b/ui/build.gradle.kts new file mode 100644 index 00000000..087c5d70 --- /dev/null +++ b/ui/build.gradle.kts @@ -0,0 +1,82 @@ +@file:Suppress("UnstableApiUsage") +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.gradle.api.tasks.compile.JavaCompile + +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.kapt) +} + +android { + compileSdk = 33 + buildFeatures { + buildConfig = true + dataBinding = true + viewBinding = true + } + namespace = "com.wireguard.android" + defaultConfig { + applicationId = "com.wireguard.android" + minSdk = 21 + targetSdk = 33 + versionCode = providers.gradleProperty("wireguardVersionCode").get().toInt() + versionName = providers.gradleProperty("wireguardVersionName").get() + buildConfigField("int", "MIN_SDK_VERSION", minSdk.toString()) + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + isCoreLibraryDesugaringEnabled = true + } + buildTypes { + release { + isMinifyEnabled = true + isShrinkResources = true + proguardFiles("proguard-android-optimize.txt") + packaging { + resources { + excludes += "DebugProbesKt.bin" + excludes += "kotlin-tooling-metadata.json" + } + } + } + debug { + applicationIdSuffix = ".debug" + versionNameSuffix = "-debug" + } + } + lint { + disable.add("LongLogTag") + warning.add("MissingTranslation") + warning.add("ImpliedQuantity") + } +} + +dependencies { + implementation(project(":tunnel")) + implementation(libs.androidx.activity.ktx) + implementation(libs.androidx.annotation) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.constraintlayout) + implementation(libs.androidx.coordinatorlayout) + implementation(libs.androidx.biometric) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.fragment.ktx) + implementation(libs.androidx.preference.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.datastore.preferences) + implementation(libs.google.material) + implementation(libs.zxing.android.embedded) + implementation(libs.kotlinx.coroutines.android) + coreLibraryDesugaring(libs.desugarJdkLibs) +} + +tasks.withType().configureEach { + options.compilerArgs.add("-Xlint:unchecked") + options.isDeprecation = true +} + +tasks.withType().configureEach { + kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString() +} diff --git a/version.gradle b/version.gradle deleted file mode 100644 index 256ceb80..00000000 --- a/version.gradle +++ /dev/null @@ -1,6 +0,0 @@ -buildscript { - ext { - wireguardVersionCode = 501 - wireguardVersionName = '1.0.20230502' - } -}