From cb43507dde8c9355581146077534d7519558c1f7 Mon Sep 17 00:00:00 2001 From: Ahmed Moussa Date: Sat, 2 Mar 2024 02:59:18 +0200 Subject: [PATCH] chore: update gradle Signed-off-by: Ahmed Moussa --- .github/workflows/pull-request.yml | 8 +- .../anoncred-wrapper-rust/build.gradle.kts | 6 +- anoncred-kmm/anoncreds-kmp/build.gradle.kts | 183 +++++++++--------- anoncred-kmm/build.gradle.kts | 27 ++- .../gradle/wrapper/gradle-wrapper.properties | 2 +- 5 files changed, 125 insertions(+), 101 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 8510b0dc..fe1a1749 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -10,7 +10,7 @@ concurrency: cancel-in-progress: true env: - JAVA_VERSION: 11 + JAVA_VERSION: 17 ATALA_GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }} ATALA_GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }} @@ -21,20 +21,20 @@ jobs: runs-on: macos-latest steps: - name: "Checkout the repo" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive token: ${{ secrets.ATALA_GITHUB_TOKEN }} fetch-depth: 0 - name: "Install Java ${{ env.JAVA_VERSION }}" - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: "${{ env.JAVA_VERSION }}" distribution: zulu - name: "Gradle Build Action" - uses: gradle/gradle-build-action@v2 + uses: gradle/actions/setup-gradle@v3 - name: "Test Kotlin code is properly formatted" working-directory: ./anoncred-kmm diff --git a/anoncred-kmm/anoncred-wrapper-rust/build.gradle.kts b/anoncred-kmm/anoncred-wrapper-rust/build.gradle.kts index 57d0c6d7..a01216d9 100644 --- a/anoncred-kmm/anoncred-wrapper-rust/build.gradle.kts +++ b/anoncred-kmm/anoncred-wrapper-rust/build.gradle.kts @@ -60,7 +60,7 @@ val rustClean by tasks.register("rustClean") { description = "Delete the generated files and folders that is being generated by this Gradle Script" delete(projectDir.resolve("target")) delete(rootDir.parentFile.resolve("target")) - delete(buildDir) + delete(project.layout.buildDirectory) } tasks.matching { it.name == "clean" }.all { @@ -333,7 +333,7 @@ val copyGeneratedBinaryForAndroidX8664 by tasks.register("copyGeneratedBin duplicatesStrategy = DuplicatesStrategy.INCLUDE include("*.so", "*.a", "*.d", "*.dylib") from(projectDir.resolve("target").resolve("x86_64-linux-android").resolve("release")) - into(rootDir.resolve("anoncreds-kmp").resolve("build").resolve("generatedResources").resolve("android").resolve("main").resolve("jniLibs").resolve("x86-64")) + into(rootDir.resolve("anoncreds-kmp").resolve("build").resolve("generatedResources").resolve("android").resolve("main").resolve("jniLibs").resolve("x86_64")) dependsOn(buildAnonCredWrapperForAndroidX8664) } @@ -385,7 +385,7 @@ val copyGeneratedBinariesToCorrectLocation by tasks.register("copyGeneratedBinar val copyBindings by tasks.register("copyBindings") { group = "rust-compiling" description = "Copy generated bindings to the `anoncreds-kmm` module" - from(buildDir.resolve("generated")) + from(project.layout.buildDirectory.dir("generated")) into(rootDir.resolve("anoncreds-kmp").resolve("build").resolve("generated")) dependsOn(copyGeneratedBinariesToCorrectLocation) } diff --git a/anoncred-kmm/anoncreds-kmp/build.gradle.kts b/anoncred-kmm/anoncreds-kmp/build.gradle.kts index 5d01ea95..64d447e1 100644 --- a/anoncred-kmm/anoncreds-kmp/build.gradle.kts +++ b/anoncred-kmm/anoncreds-kmp/build.gradle.kts @@ -1,18 +1,22 @@ import org.gradle.internal.os.OperatingSystem import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import java.util.Base64 val os: OperatingSystem = OperatingSystem.current() +val publishedMavenId: String = "io.iohk.atala.prism.anoncredskmp" plugins { - kotlin("multiplatform") id("com.android.library") + kotlin("multiplatform") + id("org.jetbrains.dokka") id("maven-publish") + id("signing") } apply(plugin = "kotlinx-atomicfu") -version = "0.4.3" -group = "io.iohk.atala.prism.anoncredskmp" +version = "0.4.4" +group = publishedMavenId fun KotlinNativeCompilation.anoncredsCinterops(type: String) { cinterops { @@ -20,8 +24,7 @@ fun KotlinNativeCompilation.anoncredsCinterops(type: String) { val crate = this.name packageName("$crate.cinterop") header( - buildDir - .resolve("generated") + project.layout.buildDirectory.asFile.get() .resolve("nativeInterop") .resolve("cinterop") .resolve("headers") @@ -43,6 +46,7 @@ fun KotlinNativeCompilation.anoncredsCinterops(type: String) { .absolutePath ) } + "macosArm64" -> { extraOpts( "-libraryPath", @@ -54,6 +58,7 @@ fun KotlinNativeCompilation.anoncredsCinterops(type: String) { .absolutePath ) } + "ios" -> { extraOpts( "-libraryPath", @@ -65,6 +70,7 @@ fun KotlinNativeCompilation.anoncredsCinterops(type: String) { .absolutePath ) } + else -> { throw GradleException("Unsupported linking") } @@ -73,96 +79,64 @@ fun KotlinNativeCompilation.anoncredsCinterops(type: String) { } } +/** + * The `javadocJar` variable is used to register a `Jar` task to generate a Javadoc JAR file. + * The Javadoc JAR file is created with the classifier "javadoc" and it includes the HTML documentation generated + * by the `dokkaHtml` task. + */ +val javadocJar by tasks.registering(Jar::class) { + archiveClassifier.set("javadoc") + from(tasks.dokkaHtml) +} + kotlin { jvm { compilations.all { - kotlinOptions.jvmTarget = "11" + kotlinOptions.jvmTarget = "17" } testRuns["test"].executionTask.configure { useJUnitPlatform() } - } - androidTarget { - publishAllLibraryVariants() - } - -// if (os.isMacOsX) { -// macosX64("native") { -// compilations.getByName("main") { -// this.anoncredsCinterops("macosX64") -// } -// } -// if (System.getProperty("os.arch") != "x86_64") { -// macosArm64 { -// compilations.getByName("main") { -// this.anoncredsCinterops("macosArm64") -// } -// } -// } -// } - -/* - val crateTargetLibDir = rootDir.resolve("anoncred-wrapper-rust").resolve("target").resolve("debug") - val hostOs = System.getProperty("os.name") - val isMingwX64 = hostOs.startsWith("Windows") - val nativeTarget = when { - hostOs == "Mac OS X" -> { - if (System.getProperty("os.arch") != "x86_64") { - macosArm64("native") - } else { - macosX64("native") + publishing { + publications { + withType { + artifact(javadocJar) + } } } - hostOs == "Linux" -> linuxArm64("native") - isMingwX64 -> mingwX64("native") - else -> throw GradleException("Host OS is not supported in Kotlin/Native.") } - nativeTarget.apply { - compilations.getByName("main") { - println("nativeTarget-only-main") - cinterops { - val anoncreds_wrapper by creating { - val crate = this.name - packageName("$crate.cinterop") - header( - generatedDir.resolve("nativeInterop").resolve("cinterop").resolve("headers") - .resolve(crate).resolve("$crate.h") - ) - tasks.named(interopProcessingTaskName) { - dependsOn(":anoncred-wrapper-rust:buildRust") - } - extraOpts("-libraryPath", crateTargetLibDir.absolutePath) - } - } + androidTarget { + publishAllLibraryVariants() + compilations.all { + kotlinOptions.jvmTarget = "17" } } -*/ sourceSets { val commonMain by getting { - val generatedDir = buildDir + val generatedDir = project.layout.buildDirectory.asFile.get() .resolve("generated") .resolve("commonMain") .resolve("kotlin") kotlin.srcDir(generatedDir) dependencies { - implementation("com.squareup.okio:okio:3.4.0") - implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1") + implementation("com.squareup.okio:okio:3.7.0") + implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0") } } val commonTest by getting { dependencies { implementation(kotlin("test")) - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0") } } val jvmMain by getting { - val generatedDir = buildDir + val generatedDir = project.layout.buildDirectory.asFile.get() .resolve("generated") .resolve("jvmMain") .resolve("kotlin") kotlin.srcDir(generatedDir) - val generatedResources = buildDir + val generatedResources = project.layout.buildDirectory.asFile.get() .resolve("generatedResources") .resolve("jvm") .resolve("main") @@ -173,12 +147,12 @@ kotlin { } val jvmTest by getting val androidMain by getting { - val generatedDir = buildDir + val generatedDir = project.layout.buildDirectory.asFile.get() .resolve("generated") .resolve("androidMain") .resolve("kotlin") kotlin.srcDir(generatedDir) - val generatedResources = buildDir + val generatedResources = project.layout.buildDirectory.asFile.get() .resolve("generatedResources") .resolve("android") .resolve("main") @@ -193,21 +167,6 @@ kotlin { implementation("junit:junit:4.13.2") } } -// if (os.isMacOsX) { -// val nativeMain by getting { // aka "macosX64" -// val generatedDir = buildDir -// .resolve("generated") -// .resolve("nativeMain") -// .resolve("kotlin") -// kotlin.srcDir(generatedDir) -// } -// val nativeTest by getting -// if (System.getProperty("os.arch") != "x86_64") { -// val macosArm64Main by getting { -// dependsOn(nativeMain) -// } -// } -// } all { languageSettings { optIn("kotlin.RequiresOptIn") @@ -227,6 +186,53 @@ val rustClean by tasks.register("rustClean") { } publishing { + publications { + withType { + groupId = publishedMavenId + artifactId = project.name + version = project.version.toString() + pom { + name.set("AnonCred KMP Wrapper") + description.set("The AnonCreds (Anonymous Credentials) specification is based on the open source verifiable credential implementation of AnonCreds that has been in use since 2017, initially as part of the Hyperledger Indy open source project and now in the Hyperledger AnonCreds project. The extensive use of AnonCreds around the world has made it a de facto standard for ZKP-based verifiable credentials, and this specification is the formalization of that implementation.") + url.set("https://docs.atalaprism.io/") + organization { + name.set("IOG") + url.set("https://iog.io/") + } + issueManagement { + system.set("Github") + url.set("https://github.com/input-output-hk/anoncreds-rs") + } + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + developers { + developer { + id.set("hamada147") + name.set("Ahmed Moussa") + email.set("ahmed.moussa@iohk.io") + organization.set("IOG") + roles.add("developer") + url.set("https://github.com/hamada147") + } + } + scm { + connection.set("scm:git:git://input-output-hk/anoncreds-rs.git") + developerConnection.set("scm:git:ssh://input-output-hk/anoncreds-rs.git") + url.set("https://github.com/input-output-hk/anoncreds-rs") + } + } + signing { + val base64EncodedAsciiArmoredSigningKey: String = System.getenv("BASE64_ARMORED_GPG_SIGNING_KEY_MAVEN") ?: "" + val signingKeyPassword: String = System.getenv("SIGNING_KEY_PASSWORD") ?: "" + useInMemoryPgpKeys(String(Base64.getDecoder().decode(base64EncodedAsciiArmoredSigningKey.toByteArray())), signingKeyPassword) + sign(this@withType) + } + } + } repositories { maven { this.name = "GitHubPackages" @@ -241,14 +247,14 @@ publishing { android { ndkVersion = "26.0.10792818" - compileSdk = 33 + compileSdk = 34 namespace = "io.iohk.atala.prism.anoncredskmp" sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") sourceSets["main"].jniLibs { setSrcDirs( listOf( - buildDir + project.layout.buildDirectory.asFile.get() .resolve("generatedResources") .resolve("android") .resolve("main") @@ -258,11 +264,10 @@ android { } defaultConfig { minSdk = 21 - targetSdk = 32 } compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } /** * Because Software Components will not be created automatically for Maven publishing from @@ -286,10 +291,10 @@ afterEvaluate { tasks.withType { dependsOn(":anoncred-wrapper-rust:buildRust") } - tasks.named("lintAnalyzeDebug") { - this.enabled = false + tasks.named("packageDebugResources") { + dependsOn(":anoncred-wrapper-rust:copyBindings") } - tasks.named("lintAnalyzeRelease") { - this.enabled = false + tasks.named("packageReleaseResources") { + dependsOn(":anoncred-wrapper-rust:copyBindings") } } diff --git a/anoncred-kmm/build.gradle.kts b/anoncred-kmm/build.gradle.kts index cb29dbdc..a4f76209 100644 --- a/anoncred-kmm/build.gradle.kts +++ b/anoncred-kmm/build.gradle.kts @@ -1,6 +1,9 @@ plugins { id("org.jlleitschuh.gradle.ktlint") version "11.6.0" - kotlin("jvm") version "1.8.20" + kotlin("jvm") version "1.9.22" + id("com.android.library") version "8.1.4" apply false + id("org.jetbrains.dokka") version "1.9.20" + id("io.github.gradle-nexus.publish-plugin") version "2.0.0-rc-1" } buildscript { @@ -11,12 +14,17 @@ buildscript { mavenCentral() } dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21") - classpath("com.android.tools.build:gradle:7.2.2") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22") classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.21.0") } } +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} + allprojects { repositories { mavenLocal() @@ -47,8 +55,19 @@ subprojects { exclude("**/generated/**") exclude { projectDir.toURI().relativize(it.file.toURI()).path.contains("/generated/") } exclude { element -> element.file.path.contains("generated/") } - exclude { it.file.path.contains("$buildDir/generated/") } + exclude("${project.layout.buildDirectory.asFile.get()}/generated/") exclude { it.file.path.contains(layout.buildDirectory.dir("generated").get().toString()) } } } } + +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/")) + username.set(System.getenv("SONATYPE_USERNAME")) + password.set(System.getenv("SONATYPE_PASSWORD")) + } + } +} diff --git a/anoncred-kmm/gradle/wrapper/gradle-wrapper.properties b/anoncred-kmm/gradle/wrapper/gradle-wrapper.properties index f398c33c..744c64d1 100644 --- a/anoncred-kmm/gradle/wrapper/gradle-wrapper.properties +++ b/anoncred-kmm/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists