From 97c87b3a20d38fc245f22c52d8ed19a99e32283e Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Sun, 25 Feb 2024 16:04:54 -0500 Subject: [PATCH 1/3] Convert app and demo build file to Kotlin DSL --- README.md | 2 +- build.gradle => build.gradle.kts | 8 +-- demo/build.gradle | 82 ------------------------------- demo/build.gradle.kts | 84 ++++++++++++++++++++++++++++++++ demo/proguard-rules.pro | 2 +- docs/BUILD-PROJECT.md | 2 +- docs/INSTALLATION.md | 6 +-- turbo/proguard-rules.pro | 2 +- 8 files changed, 95 insertions(+), 93 deletions(-) rename build.gradle => build.gradle.kts (58%) delete mode 100644 demo/build.gradle create mode 100644 demo/build.gradle.kts diff --git a/README.md b/README.md index 9073475f..c4f01000 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## Requirements -1. Android SDK 26+ is required as the `minSdkVersion` in your `build.gradle.kts` file. +1. Android SDK 26+ is required as the `minSdk` in your `build.gradle.kts` file. 1. This library is written entirely in [Kotlin](https://kotlinlang.org/), and your app should use Kotlin as well. Compatibility with Java is not provided or supported. 1. This library supports web apps using either Turbo 7 or Turbolinks 5. 1. `Turbo` (or `Turbolinks`) is exposed on the `window` object on the WebView page being loaded. diff --git a/build.gradle b/build.gradle.kts similarity index 58% rename from build.gradle rename to build.gradle.kts index 855c819c..cd4080c2 100644 --- a/build.gradle +++ b/build.gradle.kts @@ -7,8 +7,8 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:8.1.4' - classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0' + classpath("com.android.tools.build:gradle:8.1.4") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10") } } @@ -19,6 +19,6 @@ allprojects { } } -task clean(type: Delete) { - delete rootProject.buildDir +tasks.register("clean").configure { + delete(rootProject.buildDir) } diff --git a/demo/build.gradle b/demo/build.gradle deleted file mode 100644 index 47139b63..00000000 --- a/demo/build.gradle +++ /dev/null @@ -1,82 +0,0 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlinx-serialization' - -buildscript { - repositories { - google() - mavenCentral() - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-serialization:1.8.0" - } -} - -android { - compileSdk 34 - - defaultConfig { - applicationId "dev.hotwire.turbo.demo" - minSdkVersion 26 - targetSdkVersion 34 - versionCode 1 - versionName "1.0" - vectorDrawables.useSupportLibrary = true - } - - buildFeatures { - viewBinding = true - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - - debug { - debuggable true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - - kotlinOptions { - jvmTarget = "17" - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } - - sourceSets { - main.java.srcDirs += 'src/main/kotlin' - test.java.srcDirs += 'src/test/kotlin' - debug.java.srcDirs += 'src/debug/kotlin' - } - - lint { - lintConfig = file("android-lint.xml") - } - - namespace 'dev.hotwire.turbo.demo' -} - -dependencies { - implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.google.android.material:material:1.10.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation 'androidx.recyclerview:recyclerview:1.3.2' - implementation 'androidx.browser:browser:1.7.0' - implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0' - implementation 'com.github.bumptech.glide:glide:4.15.1' - implementation 'dev.hotwire:strada:1.0.0-beta2' - - implementation project(':turbo') -} - -repositories { - google() - mavenCentral() -} diff --git a/demo/build.gradle.kts b/demo/build.gradle.kts new file mode 100644 index 00000000..9539247a --- /dev/null +++ b/demo/build.gradle.kts @@ -0,0 +1,84 @@ +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") + id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10" +} + +buildscript { + repositories { + google() + mavenCentral() + } + + dependencies { + classpath("org.jetbrains.kotlin:kotlin-serialization:1.9.10") + } +} + +android { + compileSdk = 34 + + defaultConfig { + applicationId = "dev.hotwire.turbo.demo" + minSdk = 26 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + vectorDrawables.useSupportLibrary = true + } + + buildFeatures { + viewBinding = true + } + + buildTypes { + getByName("release") { + isMinifyEnabled = false + setProguardFiles(listOf(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")) + } + + getByName("debug") { + isDebuggable = true + setProguardFiles(listOf(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")) + } + } + + kotlinOptions { + jvmTarget = "17" + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + sourceSets { + named("main") { java { srcDirs("src/main/kotlin") } } + named("test") { java { srcDirs("src/test/kotlin") } } + named("debug") { java { srcDirs("src/debug/kotlin") } } + } + + lint { + lintConfig = file("android-lint.xml") + } + + namespace = "dev.hotwire.turbo.demo" +} + +dependencies { + implementation(fileTree(mapOf("include" to listOf("*.jar"), "dir" to "libs"))) + implementation("com.google.android.material:material:1.11.0") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + implementation("androidx.recyclerview:recyclerview:1.3.2") + implementation("androidx.browser:browser:1.7.0") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") + implementation("com.github.bumptech.glide:glide:4.15.1") + implementation("dev.hotwire:strada:1.0.0-beta2") + + implementation(project(":turbo")) +} + +repositories { + google() + mavenCentral() +} diff --git a/demo/proguard-rules.pro b/demo/proguard-rules.pro index f1b42451..2f9dc5a4 100644 --- a/demo/proguard-rules.pro +++ b/demo/proguard-rules.pro @@ -1,6 +1,6 @@ # Add project specific ProGuard rules here. # You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. +# proguardFiles setting in build.gradle.kts. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html diff --git a/docs/BUILD-PROJECT.md b/docs/BUILD-PROJECT.md index b26d7f67..2b918f33 100644 --- a/docs/BUILD-PROJECT.md +++ b/docs/BUILD-PROJECT.md @@ -2,7 +2,7 @@ ## From Android Studio: -- Open the [project's Gradle file](../build.gradle). +- Open the [project's Gradle file](../build.gradle.kts). - In the menu, choose Build --> Rebuild project. ## From command line: diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md index 35917321..3b59b7c4 100644 --- a/docs/INSTALLATION.md +++ b/docs/INSTALLATION.md @@ -14,15 +14,15 @@ dependencies { See the [latest version](https://search.maven.org/artifact/dev.hotwire/turbo) available on Maven Central. -## Required `minSdkVersion` +## Required `minSdk` -Android SDK 26 (or greater) is required as the `minSdkVersion` in your app module's `build.gradle.kts` file: +Android SDK 26 (or greater) is required as the `minSdk` in your app module's `build.gradle.kts` file: ```kotlin compileSdk = 34 defaultConfig { - minSdkVersion = 26 + minSdk = 26 targetSdk = 34 // ... } diff --git a/turbo/proguard-rules.pro b/turbo/proguard-rules.pro index 58fe3dcd..9e9e5917 100644 --- a/turbo/proguard-rules.pro +++ b/turbo/proguard-rules.pro @@ -2,7 +2,7 @@ # By default, the flags in this file are appended to flags specified # in /Users/dankim/android/sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. +# directive in build.gradle.kts. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html From d0e24ace094505eeb6cbe585386ef83200a425e6 Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Mon, 26 Feb 2024 09:43:30 -0500 Subject: [PATCH 2/3] 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") + } + } + } + } +} From 52ed71e6e1f004be30d6686893fd07f1886619d2 Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Mon, 26 Feb 2024 10:23:04 -0500 Subject: [PATCH 3/3] Use the Java version contant instead of a string --- demo/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/build.gradle.kts b/demo/build.gradle.kts index 9539247a..ef29a1c2 100644 --- a/demo/build.gradle.kts +++ b/demo/build.gradle.kts @@ -44,7 +44,7 @@ android { } kotlinOptions { - jvmTarget = "17" + jvmTarget = JavaVersion.VERSION_17.toString() } compileOptions {