gradle: convert build files to Kotlin

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2023-05-03 00:43:18 +05:30 committed by Jason A. Donenfeld
parent 7d91666860
commit bed2f2e5d6
12 changed files with 278 additions and 302 deletions

View File

@ -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"

13
build.gradle.kts Normal file
View File

@ -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"
}
}

View File

@ -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

29
gradle/libs.versions.toml Normal file
View File

@ -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" }

View File

@ -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'

22
settings.gradle.kts Normal file
View File

@ -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")

View File

@ -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"

129
tunnel/build.gradle.kts Normal file
View File

@ -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<MavenPublication>("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)
}

View File

@ -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
}

View File

@ -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
}

82
ui/build.gradle.kts Normal file
View File

@ -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<JavaCompile>().configureEach {
options.compilerArgs.add("-Xlint:unchecked")
options.isDeprecation = true
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
}

View File

@ -1,6 +0,0 @@
buildscript {
ext {
wireguardVersionCode = 501
wireguardVersionName = '1.0.20230502'
}
}