From d0e24ace094505eeb6cbe585386ef83200a425e6 Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Mon, 26 Feb 2024 09:43:30 -0500 Subject: [PATCH] Convert library module build file to Kotlin DSL --- turbo/build.gradle | 204 ---------------------------------------- turbo/build.gradle.kts | 208 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+), 204 deletions(-) delete mode 100644 turbo/build.gradle create mode 100644 turbo/build.gradle.kts diff --git a/turbo/build.gradle b/turbo/build.gradle deleted file mode 100644 index b15bc5a1..00000000 --- a/turbo/build.gradle +++ /dev/null @@ -1,204 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-kapt' -apply plugin: 'maven-publish' -apply plugin: 'signing' - -ext { - libVersionName = version - libraryName = 'Turbo Native for Android' - libraryDescription = 'Android framework for making Turbo native apps' - - publishedGroupId = 'dev.hotwire' - publishedArtifactId = 'turbo' - - siteUrl = 'https://github.com/hotwired/turbo-android' - gitUrl = 'https://github.com/hotwired/turbo-android.git' - - licenseType = 'MIT License' - licenseUrl = 'https://github.com/hotwired/turbo-android/blob/main/LICENSE' - - developerId = 'basecamp' - developerEmail = 'androidteam@basecamp.com' - - isSonatypeRelease = project.hasProperty('sonatype') -} - -repositories { - google() - mavenCentral() -} - -android { - compileSdk 34 - testOptions.unitTests.includeAndroidResources = true - - defaultConfig { - minSdkVersion 26 - targetSdkVersion 34 - - // Define ProGuard rules for this android library project. These rules will be applied when - // a consumer of this library sets 'minifyEnabled true'. - consumerProguardFiles 'proguard-consumer-rules.pro' - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } - - kotlinOptions { - jvmTarget = "17" - } - - buildTypes { - release { - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - - sourceSets { - main.java.srcDirs += 'src/main/kotlin' - test.java.srcDirs += 'src/test/kotlin' - debug.java.srcDirs += 'src/debug/kotlin' - } - namespace 'dev.hotwire.turbo' - - buildFeatures { - buildConfig true - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'org.jetbrains.kotlin:kotlin-reflect:1.9.10' - implementation 'com.google.android.material:material:1.10.0' - - // AndroidX - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' - - // JSON - implementation 'com.google.code.gson:gson:2.10.1' - - // Networking/API - implementation 'com.squareup.okhttp3:okhttp:4.11.0' - implementation 'com.squareup.okhttp3:logging-interceptor:4.11.0' - - // Coroutines - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3' - - // Exported AndroidX dependencies - api 'androidx.appcompat:appcompat:1.6.1' - api 'androidx.core:core-ktx:1.12.0' - api 'androidx.webkit:webkit:1.8.0' - api 'androidx.activity:activity-ktx:1.8.1' - api 'androidx.fragment:fragment-ktx:1.6.2' - api 'androidx.navigation:navigation-fragment-ktx:2.7.5' - api 'androidx.navigation:navigation-ui-ktx:2.7.5' - - // Tests - testImplementation 'androidx.test:core:1.5.0' // Robolectric - testImplementation 'androidx.navigation:navigation-testing:2.7.5' - testImplementation 'androidx.arch.core:core-testing:2.2.0' - testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3' - testImplementation 'org.assertj:assertj-core:3.24.2' - testImplementation 'org.robolectric:robolectric:4.9.2' - testImplementation 'org.mockito:mockito-core:5.2.0' - testImplementation 'com.nhaarman:mockito-kotlin:1.6.0' - testImplementation 'com.squareup.okhttp3:mockwebserver:4.11.0' - testImplementation 'junit:junit:4.13.2' -} - -// Use the sources jar when publishing -task androidSourcesJar(type: Jar) { - archiveClassifier.set("sources") - from android.sourceSets.main.java.srcDirs -} - -// Only sign Sonatype release artifacts -tasks.withType(Sign) { - onlyIf { isSonatypeRelease } -} - -// Sign Sonatype published release artifacts -if (isSonatypeRelease) { - signing { - def keyId = System.getenv('GPG_KEY_ID') - def secretKey = System.getenv("GPG_SECRET_KEY") - def password = System.getenv("GPG_PASSWORD") - - useInMemoryPgpKeys(keyId, secretKey, password) - - required { gradle.taskGraph.hasTask("publish") } - sign publishing.publications - } -} - -// Publish to GitHub Packages via ./gradlew -Pversion= clean build publish -// https://github.com/orgs/hotwired/packages?repo_name=turbo-android -afterEvaluate { - publishing { - publications { - release(MavenPublication) { - pom { - name = libraryName - description = libraryDescription - url = siteUrl - licenses { - license { - name = licenseType - url = licenseUrl - } - } - developers { - developer { - id = developerId - name = developerId - email = developerEmail - } - } - scm { - url = gitUrl - } - } - - // Applies the component for the release build variant - from components.release - - // Add sources as separate jar - artifact androidSourcesJar - - // Publication attributes - groupId = publishedGroupId - artifactId = publishedArtifactId - version = libVersionName - } - } - repositories { - if (isSonatypeRelease) { - maven { - url = uri('https://s01.oss.sonatype.org/content/repositories/releases/') - - credentials { - username = System.getenv('SONATYPE_USER') - password = System.getenv('SONATYPE_PASSWORD') - } - } - } else { - maven { - name = 'GitHubPackages' - url = uri('https://maven.pkg.github.com/hotwired/turbo-android') - - credentials { - username = System.getenv('GITHUB_ACTOR') - password = System.getenv('GITHUB_TOKEN') - } - } - } - } - } -} diff --git a/turbo/build.gradle.kts b/turbo/build.gradle.kts new file mode 100644 index 00000000..8d6bea18 --- /dev/null +++ b/turbo/build.gradle.kts @@ -0,0 +1,208 @@ +plugins { + id("com.android.library") + id("kotlin-android") + id("kotlin-kapt") + id("maven-publish") + id("signing") +} + +val libVersionName by extra(version as String) +val libraryName by extra("Turbo Native for Android") +val libraryDescription by extra("Android framework for making Turbo native apps") + +val publishedGroupId by extra("dev.hotwire") +val publishedArtifactId by extra("turbo") + +val siteUrl by extra("https://github.com/hotwired/turbo-android") +val gitUrl by extra("https://github.com/hotwired/turbo-android.git") + +val licenseType by extra("MIT License") +val licenseUrl by extra("https://github.com/hotwired/turbo-android/blob/main/LICENSE") + +val developerId by extra("basecamp") +val developerEmail by extra("androidteam@basecamp.com") + +val isSonatypeRelease by extra(project.hasProperty("sonatype")) + +repositories { + google() + mavenCentral() +} + +android { + compileSdk = 34 + testOptions.unitTests.isIncludeAndroidResources = true + + defaultConfig { + minSdk = 26 + targetSdk = 34 + + // Define ProGuard rules for this android library project. These rules will be applied when + // a consumer of this library sets 'minifyEnabled true'. + consumerProguardFiles("proguard-consumer-rules.pro") + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_17.toString() + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + buildTypes { + getByName("release") { + isMinifyEnabled = true + setProguardFiles(listOf(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")) + } + } + + sourceSets { + named("main") { java { srcDirs("src/main/kotlin") } } + named("test") { java { srcDirs("src/test/kotlin") } } + named("debug") { java { srcDirs("src/debug/kotlin") } } + } + + namespace = "dev.hotwire.turbo" + + buildFeatures { + buildConfig = true + } + + publishing { + singleVariant("release") { + withSourcesJar() + } + } +} + +dependencies { + implementation(fileTree(mapOf("include" to listOf("*.jar"), "dir" to "libs"))) + implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.10") + implementation("com.google.android.material:material:1.11.0") + + // AndroidX + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + implementation("androidx.lifecycle:lifecycle-extensions:2.2.0") + implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0") + + // JSON + implementation("com.google.code.gson:gson:2.10.1") + + // Networking/API + implementation("com.squareup.okhttp3:okhttp:4.11.0") + implementation("com.squareup.okhttp3:logging-interceptor:4.11.0") + + // Coroutines + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") + + // Exported AndroidX dependencies + api("androidx.appcompat:appcompat:1.6.1") + api("androidx.core:core-ktx:1.12.0") + api("androidx.webkit:webkit:1.8.0") + api("androidx.activity:activity-ktx:1.8.1") + api("androidx.fragment:fragment-ktx:1.6.2") + api("androidx.navigation:navigation-fragment-ktx:2.7.5") + api("androidx.navigation:navigation-ui-ktx:2.7.5") + + // Tests + testImplementation("androidx.test:core:1.5.0") // Robolectric + testImplementation("androidx.navigation:navigation-testing:2.7.5") + testImplementation("androidx.arch.core:core-testing:2.2.0") + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3") + testImplementation("org.assertj:assertj-core:3.24.2") + testImplementation("org.robolectric:robolectric:4.9.2") + testImplementation("org.mockito:mockito-core:5.2.0") + testImplementation("com.nhaarman:mockito-kotlin:1.6.0") + testImplementation("com.squareup.okhttp3:mockwebserver:4.11.0") + testImplementation("junit:junit:4.13.2") +} + +tasks { + // Only sign Sonatype release artifacts + withType().configureEach { + onlyIf { isSonatypeRelease } + } +} + +// Sign Sonatype published release artifacts +if (isSonatypeRelease) { + signing { + val keyId = System.getenv("GPG_KEY_ID") + val secretKey = System.getenv("GPG_SECRET_KEY") + val password = System.getenv("GPG_PASSWORD") + + useInMemoryPgpKeys(keyId, secretKey, password) + + setRequired({ gradle.taskGraph.hasTask("publish") }) + sign(publishing.publications) + } +} + +// Publish to GitHub Packages via: +// ./gradlew -Pversion= clean build publish +// https://github.com/orgs/hotwired/packages?repo_name=turbo-android +// Publish to Maven Central via: +// ./gradlew -Psonatype -Pversion= clean build publish +// https://search.maven.org/artifact/dev.hotwire/turbo +publishing { + publications { + register("release") { + groupId = publishedGroupId + artifactId = publishedArtifactId + version = libVersionName + + pom { + name.set(libraryName) + description.set(libraryDescription) + url.set(siteUrl) + + licenses { + license { + name.set(licenseType) + url.set(licenseUrl) + } + } + developers { + developer { + id.set(developerId) + name.set(developerId) + email.set(developerEmail) + } + } + scm { + url.set(gitUrl) + } + } + + // Applies the component for the release build variant + afterEvaluate { + from(components["release"]) + } + } + } + repositories { + if (isSonatypeRelease) { + maven { + url = uri("https://s01.oss.sonatype.org/content/repositories/releases/") + + credentials { + username = System.getenv("SONATYPE_USER") + password = System.getenv("SONATYPE_PASSWORD") + } + } + } else { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/hotwired/turbo-android") + + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } + } +}