diff --git a/.circleci/config.yml b/.circleci/config.yml index 7930d5b9..49a05c13 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,7 +12,7 @@ jobs: steps: - checkout - restore_cache: - key: jars-{{ checksum "build.gradle" }}-{{ checksum "lib/build.gradle" }} + key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} - run: name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. command: sudo chmod +x ./gradlew @@ -25,13 +25,10 @@ jobs: - save_cache: paths: - ~/.gradle - key: jars-{{ checksum "build.gradle" }}-{{ checksum "lib/build.gradle" }} + key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} - run: name: Run Tests - command: ./gradlew lib:testDebugUnitTest lib:jacocoTestReport - # - run: - # name: Upload Coverage Report to SonarCloud - # command: ./gradlew sonarqube + command: ./gradlew lib:testDebugUnitTest - store_test_results: path: lib/build/test-results/testDebugUnitTest deploy-to-sonatype: @@ -42,7 +39,7 @@ jobs: steps: - checkout - restore_cache: - key: jars-{{ checksum "build.gradle" }}-{{ checksum "lib/build.gradle" }} + key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} - run: name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. command: sudo chmod +x ./gradlew @@ -55,7 +52,7 @@ jobs: - save_cache: paths: - ~/.gradle - key: jars-{{ checksum "build.gradle" }}-{{ checksum "lib/build.gradle" }} + key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "lib/build.gradle.kts" }} - run: name: Snapshot Release Check command: | diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 0679a3d6..00000000 --- a/build.gradle +++ /dev/null @@ -1,31 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - ext { - coverageExclusions = ['**/BR.*', - '**/R.class', - '**/R$*.class', - '**/BuildConfig.*', - '**/Manifest*.*', - '**/*Test*.*', - 'android/**/*.*', - 'androidx/**/*.*',] - } - dependencies { - classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1" - classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0" - classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3" - } -} - -plugins { - id 'org.jlleitschuh.gradle.ktlint' version '10.1.0' apply false - id 'com.android.library' version '8.5.0' apply false - id 'org.jetbrains.kotlin.android' version '1.8.20' apply false - id "com.autonomousapps.dependency-analysis" version "1.20.0" -} - -apply from: 'sonarqube.gradle' - -task clean(type: Delete) { - delete rootProject.buildDir -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..a750f8e1 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,19 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + dependencies { + classpath("com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1") + classpath("org.jlleitschuh.gradle:ktlint-gradle:10.1.0") + classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3") + } +} + +plugins { + id("org.jlleitschuh.gradle.ktlint") version "10.1.0" apply false + id("com.android.library") version "8.5.0" apply false + id("org.jetbrains.kotlin.android") version "1.8.20" apply false + id("com.autonomousapps.dependency-analysis") version "1.20.0" +} + +tasks.register("clean").configure { + delete(rootProject.layout.buildDirectory) + } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 210984b0..443b8945 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,5 +22,5 @@ android.nonTransitiveRClass=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official android.nonFinalResIds=false -VERSION_NAME=1.0.5 +LIBRARY_VERSION=1.0.5 MAPBOX_DOWNLOADS_TOKEN = "YOUR_MAPBOX_DOWNLOADS_TOKEN" \ No newline at end of file diff --git a/jacoco.gradle b/jacoco.gradle deleted file mode 100644 index b1c4584c..00000000 --- a/jacoco.gradle +++ /dev/null @@ -1,34 +0,0 @@ -apply plugin: 'jacoco' - -ext { - coverageExclusions = [ - '**/*Activity*.*', - '**/*Fragment*.*', - '**/R.class', - '**/R$*.class', - '**/BuildConfig.*', - ] -} - -tasks.register('jacocoTestReport', JacocoReport) { - dependsOn['testDebugUnitTest'] - group = "Reporting" - description = "Generate Jacoco coverage reports for Debug build" - - - reports { - xml.required = true - html.required = true - } - - def javaTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug/classes", excludes: coverageExclusions) - def kotlinTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: coverageExclusions) - - def mainSrc = "/src/main/java" - - additionalSourceDirs.from = files(mainSrc) - sourceDirectories.from = files([mainSrc]) - classDirectories.from = files([javaTree, kotlinTree]) - - executionData.from = files("${buildDir}/jacoco/testDebugUnitTest.exec") -} \ No newline at end of file diff --git a/lib/build.gradle b/lib/build.gradle deleted file mode 100644 index 0fb37831..00000000 --- a/lib/build.gradle +++ /dev/null @@ -1,103 +0,0 @@ -plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' - id 'org.jlleitschuh.gradle.ktlint' - id 'maven-publish' - id 'signing' - id 'org.jetbrains.dokka' version '1.5.0' -} - -/** - * IS_SNAPSHOT_RELEASE property will be automatically added to the root gradle.properties file by the CI pipeline, depending on the GitHub branch. - * A snapshot release is generated for every pull request merged or commit made into an epic branch. - */ -def isSnapshotRelease = findProperty('IS_SNAPSHOT_RELEASE') == 'true' -def libVersion = isSnapshotRelease ? "${findProperty('VERSION_NAME')}-SNAPSHOT" : findProperty('VERSION_NAME') - -apply from: 'maven-push.gradle' -apply from: '../jacoco.gradle' - -android { - compileSdk 34 - - defaultConfig { - minSdk 24 - targetSdk 34 - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles "consumer-rules.pro" - } - - def filesToExclude = [ - '**/*SdkToApiExtensions*.kt', - '**/*W3WSdkDataSource*.kt' - ] - - tasks.withType(SourceTask.class).configureEach { - it.exclude(filesToExclude) - } - android.sourceSets.main.kotlin.exclude(filesToExclude) - - buildTypes { - debug { - testCoverageEnabled = false - } - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = '1.8' - } - - testOptions { - unitTests.returnDefaultValues = true - } - - buildFeatures { - viewBinding true - } - namespace 'com.what3words.map.components' - tasks.dokkaGfm.configure { - suppressObviousFunctions.set(true) - suppressInheritedMembers.set(true) - } - publishing { - singleVariant('release') { - withSourcesJar() - withJavadocJar() - } - } -} - -dependencies { - implementation "com.google.android.material:material:1.12.0" - // what3words - api "com.what3words:w3w-android-wrapper:4.0.2" - api "com.what3words:w3w-android-api-sdk-bridge:1.0.8-SNAPSHOT" - - // Google maps - compileOnly "com.google.android.gms:play-services-maps:19.0.0" - compileOnly "com.google.maps.android:android-maps-utils:3.4.0" - testImplementation "com.google.android.gms:play-services-maps:19.0.0" - - // Mapbox - compileOnly "com.mapbox.maps:android:10.18.3" - - // kotlin - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1" - testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1" - - // Testing - testImplementation "junit:junit:4.13.2" - testImplementation "androidx.test:core:1.6.1" - testImplementation "com.google.truth:truth:1.4.2" - testImplementation "io.mockk:mockk:1.13.5" - testImplementation "androidx.arch.core:core-testing:2.2.0" -} \ No newline at end of file diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts new file mode 100644 index 00000000..3f7b84e7 --- /dev/null +++ b/lib/build.gradle.kts @@ -0,0 +1,172 @@ +import java.net.URI + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.android") + id("org.jlleitschuh.gradle.ktlint") + id("maven-publish") + id("signing") + id("org.jetbrains.dokka") version "1.5.0" +} + +/** + * IS_SNAPSHOT_RELEASE property will be automatically added to the root gradle.properties file by the CI pipeline, depending on the GitHub branch. + * A snapshot release is generated for every pull request merged or commit made into an epic branch. + */ +val isSnapshotRelease = findProperty("IS_SNAPSHOT_RELEASE") == "true" +version = + if (isSnapshotRelease) "${findProperty("LIBRARY_VERSION")}-SNAPSHOT" else "${findProperty("LIBRARY_VERSION")}" + +android { + compileSdk = 34 + namespace = "com.what3words.map.components" + + defaultConfig { + minSdk = 24 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + named("debug") { + enableUnitTestCoverage = true + } + named("release") { + isMinifyEnabled = false + setProguardFiles(listOf(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")) + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } + + testOptions { + unitTests.isReturnDefaultValues = true + } + + buildFeatures { + viewBinding = true + } + + publishing { + singleVariant("release") { + withSourcesJar() + } + } +} + +dependencies { + implementation("com.google.android.material:material:1.12.0") + // what3words + api("com.what3words:w3w-android-wrapper:4.0.2") + api("com.what3words:w3w-android-api-sdk-bridge:1.0.8-SNAPSHOT") + + // Google maps + compileOnly("com.google.android.gms:play-services-maps:19.0.0") + compileOnly("com.google.maps.android:android-maps-utils:3.4.0") + testImplementation("com.google.android.gms:play-services-maps:19.0.0") + + // Mapbox + compileOnly("com.mapbox.maps:android:10.18.3") + + // kotlin + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1") + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1") + + // Testing + testImplementation("junit:junit:4.13.2") + testImplementation("androidx.test:core:1.6.1") + testImplementation("com.google.truth:truth:1.4.2") + testImplementation("io.mockk:mockk:1.13.5") + testImplementation("androidx.arch.core:core-testing:2.2.0") +} + +//region publishing + +val ossrhUsername = findProperty("OSSRH_USERNAME") as String? +val ossrhPassword = findProperty("OSSRH_PASSWORD") as String? +val signingKey = findProperty("SIGNING_KEY") as String? +val signingKeyPwd = findProperty("SIGNING_KEY_PWD") as String? + +publishing { + repositories { + maven { + name = "sonatype" + val releasesRepoUrl = + "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + val snapshotsRepoUrl = + "https://s01.oss.sonatype.org/content/repositories/snapshots/" + url = if (version.toString() + .endsWith("SNAPSHOT") + ) URI.create(snapshotsRepoUrl) else URI.create(releasesRepoUrl) + + credentials { + username = ossrhUsername + password = ossrhPassword + } + } + publications { + create("Maven") { + artifactId = "w3w-android-map-components" + groupId = "com.what3words" + version = project.version.toString() + afterEvaluate { + from(components["release"]) + } + } + withType(MavenPublication::class.java) { + val publicationName = name + val dokkaJar = + project.tasks.register("${publicationName}DokkaJar", Jar::class) { + group = JavaBasePlugin.DOCUMENTATION_GROUP + description = "Assembles Kotlin docs with Dokka into a Javadoc jar" + archiveClassifier.set("javadoc") + from(tasks.named("dokkaHtml")) + + // Each archive name should be distinct, to avoid implicit dependency issues. + // We use the same format as the sources Jar tasks. + // https://youtrack.jetbrains.com/issue/KT-46466 + archiveBaseName.set("${archiveBaseName.get()}-$publicationName") + } + artifact(dokkaJar) + pom { + name.set("w3w-android-map-components") + description.set("Android library to integrate what3words with different map providers.") + url.set("https://github.com/what3words/w3w-android-map-components") + licenses { + license { + name.set("The MIT License (MIT)") + url.set("https://github.com/what3words/w3w-android-map-components/blob/master/LICENSE") + } + } + developers { + developer { + id.set("what3words") + name.set("what3words") + email.set("development@what3words.com") + } + } + scm { + connection.set("scm:git:git://github.com/what3words/w3w-android-map-components.git") + developerConnection.set("scm:git:ssh://git@github.com:what3words/w3w-android-map-components.git") + url.set("https://github.com/what3words/w3w-android-map-components") + } + } + } + } + } +} + +signing { + useInMemoryPgpKeys(signingKey, signingKeyPwd) + sign(publishing.publications) +} + +//endregion \ No newline at end of file diff --git a/lib/maven-push.gradle b/lib/maven-push.gradle deleted file mode 100644 index bc18f6ad..00000000 --- a/lib/maven-push.gradle +++ /dev/null @@ -1,68 +0,0 @@ -def ossrhUsername = findProperty('OSSRH_USERNAME') -def ossrhPassword = findProperty('OSSRH_PASSWORD') -def signingKey = findProperty('SIGNING_KEY') -def signingKeyPwd = findProperty('SIGNING_KEY_PWD') - -/** - * IS_SNAPSHOT_RELEASE property will be automatically added to the root gradle.properties file by the CI pipeline, depending on the GitHub branch. - * A snapshot release is generated for every pull request merged or commit made into an epic branch. - */ -def isSnapshotRelease = findProperty('IS_SNAPSHOT_RELEASE') == 'true' -def libVersion = isSnapshotRelease ? "${findProperty('VERSION_NAME')}-SNAPSHOT" : findProperty('VERSION_NAME') - -afterEvaluate { - publishing { - publications { - release(MavenPublication) { - from components.release - // You can then customize attributes of the publication as shown below. - groupId = "com.what3words" - artifactId = "w3w-android-map-components" - version = libVersion - - pom { - name = "w3w-android-map-components" - description = 'Android library to integrate what3words with different map providers.' - url = 'https://github.com/what3words/w3w-android-map-components' - licenses { - license { - name = 'The MIT License (MIT)' - url = 'https://github.com/what3words/w3w-android-map-components/blob/master/LICENSE' - } - } - developers { - developer { - id = 'what3words' - name = 'what3words' - email = 'development@what3words.com' - } - } - scm { - connection = 'scm:git:git://github.com/what3words/w3w-android-map-components.git' - developerConnection = 'scm:git:ssh://git@github.com:what3words/w3w-android-map-components.git' - url = 'https://github.com/what3words/w3w-android-map-components' - } - } - } - } - repositories { - maven { - name = "sonatype" - - def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" - def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" - url = libVersion.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl - - credentials { - username ossrhUsername - password ossrhPassword - } - } - } - } -} - -signing { - useInMemoryPgpKeys(signingKey, signingKeyPwd) - sign publishing.publications -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index a2f5b4ca..00000000 --- a/settings.gradle +++ /dev/null @@ -1,36 +0,0 @@ -pluginManagement { - repositories { - gradlePluginPortal() - google() - mavenCentral() - } -} -dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) - repositories { - google() - jcenter() - mavenCentral() - maven { - url 'https://api.mapbox.com/downloads/v2/releases/maven' - authentication { - basic(BasicAuthentication) - } - credentials { - // Do not change the username below. - // This should always be `mapbox` (not your username). - username = "mapbox" - // Use the secret token you stored in gradle.properties as the password - password = MAPBOX_DOWNLOADS_TOKEN - } - } - maven { - url "https://s01.oss.sonatype.org/content/repositories/comwhat3words-1446" - } - maven { - url "https://s01.oss.sonatype.org/content/repositories/snapshots/" - } - } -} -rootProject.name = "w3w-android-components-maps" -include ':lib' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..67120e64 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,26 @@ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + maven { + url = uri("https://api.mapbox.com/downloads/v2/releases/maven") + // Do not change the username below. It should always be "mapbox" (not your username). + credentials.username = "mapbox" + // Use the secret token stored in gradle.properties as the password + credentials.password = providers.gradleProperty("MAPBOX_DOWNLOADS_TOKEN").get() + authentication.create("basic") + } + maven(url = "https://s01.oss.sonatype.org/content/repositories/comwhat3words-1446") + maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/") + } +} +rootProject.name = "w3w-android-components-maps" +include(":lib") diff --git a/sonarqube.gradle b/sonarqube.gradle deleted file mode 100644 index d03c0377..00000000 --- a/sonarqube.gradle +++ /dev/null @@ -1,26 +0,0 @@ -apply plugin: "org.sonarqube" - -sonarqube { - properties { - property "sonar.projectName", "what3words-android-map-components" - - property "sonar.projectKey", "what3words_w3w-android-map-components" - property "sonar.organization", "what3words" - property "sonar.host.url", "https://sonarcloud.io" - - property "sonar.modules", ":lib" - property "sonar.sourceEncoding", "UTF-8" - - - property "sonar.junit.reportPaths", "**/test-results/**/*.xml" - property ":lib.sonar.coverage.jacoco.xmlReportPaths", "**/jacocoTestReport/jacocoTestReport.xml" - property ":lib.sonar.sources", "src/main/java" - property ":lib.sonar.java.coveragePlugin", "jacoco" - - - property ":testing.sonar.coverage.jacoco.xmlReportPaths", "build/reports/coverage/androidTest/debug/report.xml" - property ":testing.sonar.sources", "src/main/java" - property ":testing.sonar.java.coveragePlugin", "jacoco" - - } -}