@file:Suppress("UnstableApiUsage") import com.google.protobuf.gradle.* import org.gradle.api.tasks.testing.logging.TestLogEvent val pkg: String = providers.gradleProperty("wireguardPackageName").get() plugins { alias(libs.plugins.android.library) `maven-publish` alias(libs.plugins.google.protobuf) signing } android { compileSdk = 33 compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } namespace = "${pkg}.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=${pkg}") } } } debug { externalNativeBuild { cmake { arguments("-DANDROID_PACKAGE_NAME=${pkg}.debug") } } } } lint { disable += "LongLogTag" disable += "NewApi" } publishing { singleVariant("release") { withJavadocJar() withSourcesJar() } } } dependencies { implementation(project(":bgp-java")) implementation(libs.androidx.annotation) implementation(libs.androidx.collection) implementation(libs.grpc.android) implementation(libs.grpc.okhttp) implementation(libs.grpc.protobuf.lite) implementation(libs.grpc.stub) compileOnly(libs.javax.annotation.api) compileOnly(libs.jsr305) testImplementation(libs.junit) } protobuf { protoc { // The artifact spec for the Protobuf Compiler artifact = "com.google.protobuf:protoc:${libs.versions.protoc.get()}" } plugins { // Optional: an artifact spec for a protoc plugin, with "grpc" as // the identifier, which can be referred to in the "plugins" // container of the "generateProtoTasks" closure. id("grpc") { artifact = "io.grpc:protoc-gen-grpc-java:${libs.versions.protocgengrpc.get()}" } id("java") { } } generateProtoTasks { all().forEach { task -> task.plugins{ id("grpc") { option("lite") } id("java") { option("lite") } } } } } afterEvaluate({ -> // All custom configurations created by the protobuf plugin, // are only available at this point. var protoc = configurations.named("protobufToolsLocator_protoc") var protocCache = "${gradle.gradleUserHomeDir}/caches/protoc-bin-${libs.versions.protoc.get()}" tasks.register("copyProtoc", Copy::class) { // Used by tunnel/tools/libwg-go/Makefile run in tools/CMakeLists.txt from(protoc) into(protocCache) rename("protoc-.*", "protoc") setFileMode(7 * 64 + 7 * 8 + 5) // 0775 } tasks.named("preBuild").get().dependsOn("copyProtoc") // Extract duration.proto used by external library in libwg.proto tasks.named("preDebugBuild").get().dependsOn(tasks.named("extractIncludeDebugProto").get()) tasks.named("preReleaseBuild").get().dependsOn(tasks.named("extractIncludeReleaseProto").get()) println("done afterEvaluate") }) publishing { publications { register("release") { groupId = pkg 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.environmentVariable("SONATYPE_USER").orNull password = providers.environmentVariable("SONATYPE_PASSWORD").orNull } } } } signing { useGpgCmd() sign(publishing.publications) }