Skip to content

Commit

Permalink
chore: migration to KTS (#288)
Browse files Browse the repository at this point in the history
* feat: migration to KTS

* feat: adjusted dependencies

* feat: removed Plugins

* feat: added lint report

* feat: copyright note

* feat: removed unnused extras

* feat: more updates

* feat: Kotlin 2.0.21
  • Loading branch information
kikoso authored Dec 12, 2024
1 parent 76357ee commit 403eb37
Show file tree
Hide file tree
Showing 17 changed files with 391 additions and 324 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4.2.1
uses: actions/setup-java@v4.5.0
with:
java-version: '21'
distribution: 'temurin'
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/lint-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Lint and Upload SARIF

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/[email protected]
with:
distribution: 'adopt'
java-version: '17'

- name: Run Android Lint
run: ./gradlew lint

- name: Merge SARIF files
run: |
jq -s '{ "$schema": "https://json.schemastore.org/sarif-2.1.0", "version": "2.1.0", "runs": map(.runs) | add }' maps-ktx/build/reports/lint-results.sarif maps-utils-ktx/build/reports/lint-results.sarif app/build/reports/lint-results.sarif > merged.sarif
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: merged.sarif
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up JDK
uses: actions/setup-java@v4.2.1
uses: actions/setup-java@v4.5.0
with:
java-version: '21'
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: gradle/actions/wrapper-validation@v4

- name: Set up JDK
uses: actions/setup-java@v4.2.1
uses: actions/setup-java@v4.5.0
with:
java-version: '21'
distribution: 'temurin'
Expand Down
4 changes: 2 additions & 2 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins:
- - "@google/semantic-release-replace-plugin"
- replacements:
- files:
- "build.gradle"
- "build.gradle.kts"
from: "\\bversion = '.*'"
to: "version = '${nextRelease.version}'"
- files:
Expand All @@ -18,7 +18,7 @@ plugins:
publishCmd: "./gradlew publish --warn --stacktrace"
- - "@semantic-release/git"
- assets:
- "build.gradle"
- "build.gradle.kts"
- "*.md"
- "@semantic-release/github"
options:
Expand Down
47 changes: 24 additions & 23 deletions app/build.gradle → app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2023 Google Inc.
* Copyright 2024 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,34 +15,34 @@
*/

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
id("com.android.application")
id("kotlin-android")
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
}

android {
lint {
sarifOutput = file("$buildDir/reports/lint-results.sarif")
}

compileSdk libs.versions.androidCompileSdk.get().toInteger()
compileSdk = libs.versions.androidCompileSdk.get().toInt()

defaultConfig {
applicationId "com.google.maps.android.ktx.demo"
minSdkVersion libs.versions.androidMinSdk.get().toInteger()
targetSdkVersion libs.versions.androidTargetSdk.get().toInteger()
versionCode 1
versionName "1.0"
applicationId = "com.google.maps.android.ktx.demo"
minSdk = libs.versions.androidMinSdk.get().toInt()
targetSdk = libs.versions.androidTargetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
}

buildFeatures {
buildConfig = true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}

Expand All @@ -54,26 +54,27 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}
namespace 'com.google.maps.android.ktx.demo'

namespace = "com.google.maps.android.ktx.demo"
}

dependencies {
implementation libs.kotlinStdlib
implementation libs.androidxAppcompat
implementation libs.androidxCoreKtx
implementation libs.lifecycleRuntimeKtx
implementation(libs.kotlinStdlib)
implementation(libs.androidxAppcompat)
implementation(libs.androidxCoreKtx)
implementation(libs.lifecycleRuntimeKtx)

// Instead of the lines below, regular apps would load these libraries from Maven according to
// the README installation instructions
implementation project(':maps-ktx')
implementation project(':maps-utils-ktx')
implementation(project(":maps-ktx"))
implementation(project(":maps-utils-ktx"))
}

secrets {
// To add your Maps API key to this project:
// 1. Create a file ./secrets.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
propertiesFileName 'secrets.properties'
defaultPropertiesFileName 'secrets.defaults.properties'
}
propertiesFileName = "secrets.properties"
defaultPropertiesFileName = "secrets.defaults.properties"
}
26 changes: 26 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {
`kotlin-dsl`
}

repositories {
google()
mavenCentral()
gradlePluginPortal()
}


dependencies {
implementation(libs.kotlinGradlePlugin)
implementation(libs.gradle)
implementation(libs.dokkaGradlePlugin)
implementation(libs.org.jacoco.core)
}

gradlePlugin {
plugins {
register("publishingConventionPlugin") {
id = "android.maps.ktx.PublishingConventionPlugin"
implementationClass = "PublishingConventionPlugin"
}
}
}
108 changes: 108 additions & 0 deletions build-logic/convention/src/main/kotlin/PublishingConventionPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// buildSrc/src/main/kotlin/PublishingConventionPlugin.kt
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.*
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
import org.gradle.api.tasks.testing.Test
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
import org.gradle.plugins.signing.SigningExtension
import org.gradle.api.publish.maven.*

class PublishingConventionPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.run {

applyPlugins()
configureJacoco()
configurePublishing()
configureSigning()
}
}

private fun Project.applyPlugins() {
apply(plugin = "com.android.library")
apply(plugin = "com.mxalbert.gradle.jacoco-android")
apply(plugin = "maven-publish")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "signing")
}

private fun Project.configureJacoco() {
configure<JacocoPluginExtension> {
toolVersion = "0.8.7"

}

tasks.withType<Test>().configureEach {
extensions.configure(JacocoTaskExtension::class.java) {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
}
}

private fun Project.configurePublishing() {
extensions.configure<com.android.build.gradle.LibraryExtension> {
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}
extensions.configure<PublishingExtension> {
publications {
create<MavenPublication>("aar") {
afterEvaluate {
from(components["release"])
}
pom {
name.set(project.name)
description.set("Kotlin extensions (KTX) for Google Maps SDK")
url.set("https://github.com/googlemaps/android-maps-ktx")
scm {
connection.set("scm:[email protected]:googlemaps/android-maps-ktx.git")
developerConnection.set("scm:[email protected]:googlemaps/android-maps-ktx.git")
url.set("https://github.com/googlemaps/android-maps-ktx")
}
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")
}
}
organization {
name.set("Google Inc")
url.set("http://developers.google.com/maps")
}
developers {
developer {
name.set("Google Inc.")
}
}
}
}
}
repositories {
maven {
val releasesRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotsRepoUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/")
url = if (project.version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
credentials {
username = project.findProperty("sonatypeToken") as String?
password = project.findProperty("sonatypeTokenPassword") as String?
}
}
}
}
}

private fun Project.configureSigning() {
configure<SigningExtension> {
sign(extensions.getByType<PublishingExtension>().publications["aar"])
}
}
}
14 changes: 14 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
include(":convention")
Loading

0 comments on commit 403eb37

Please sign in to comment.