-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NSDK-190] Migrate Build Configuration from Groovy to Kotlin (#102)
* Migrate settings.gradle to settings.gradle.kts * Delete virtusize.aar * Format the code * Migrate from Groovy to Kotlin * Remove .editorconfig * Create Project extension function getProperties * Apply ktlint * Fix settings.gradle.kts * Increasing the amount of JVM memory * Fix R8 error * Revert the change to the JVM memory * Bump virtusize-auth to 1.0.5 * Create reusable functions to publish * Remove constants * Update README.md * Update README.md * Make mavenPublicationName private * Modify the publish script * Rename to areSigningCredentialsProvided
- Loading branch information
Showing
204 changed files
with
6,797 additions
and
5,999 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import com.virtusize.android.extensions.getProperties | ||
|
||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
plugins { | ||
alias(libs.plugins.android.application) apply false | ||
alias(libs.plugins.android.library) apply false | ||
alias(libs.plugins.jetbrains.kotlin.android) apply false | ||
alias(libs.plugins.kotlin.parcelize) apply false | ||
alias(libs.plugins.nexus.publish) | ||
} | ||
|
||
apply(from = "${project.rootDir}/gradle/githooks.gradle.kts") | ||
apply(from = "${project.rootDir}/gradle/ktlint.gradle.kts") | ||
|
||
nexusPublishing { | ||
repositories { | ||
sonatype { | ||
// only for users registered in Sonatype after 24 Feb 2021 | ||
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) | ||
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) | ||
username = getProperties("OSSRH_USERNAME") | ||
password = getProperties("OSSRH_PASSWORD") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} |
11 changes: 11 additions & 0 deletions
11
buildSrc/src/main/java/com/virtusize/android/constants/Constants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.virtusize.android.constants | ||
|
||
object Constants { | ||
const val COMPILE_SDK = 34 | ||
const val MIN_SDK = 21 | ||
const val TARGET_SDK = 34 | ||
|
||
// Update versionName when publishing a new release | ||
const val VERSION_NAME = "2.5.5" | ||
const val GROUP_ID = "com.virtusize.android" | ||
} |
20 changes: 20 additions & 0 deletions
20
buildSrc/src/main/java/com/virtusize/android/extensions/ProjectExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.virtusize.android.extensions | ||
|
||
import org.gradle.api.Project | ||
import java.util.Properties | ||
|
||
/** | ||
* Get the value of the key from the local.properties file. | ||
* If the key is not found in the local.properties file, | ||
* it will try to get the value from the environment variables. | ||
*/ | ||
fun Project.getProperties(key: String): String? { | ||
val localPropertiesFile = file("local.properties") | ||
return if (localPropertiesFile.exists()) { | ||
Properties().apply { | ||
load(localPropertiesFile.inputStream()) | ||
}.getProperty(key) | ||
} else { | ||
System.getenv(key) | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
buildSrc/src/main/java/com/virtusize/android/extensions/Publications.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.virtusize.android.extensions | ||
|
||
import com.virtusize.android.constants.Constants | ||
import org.gradle.api.Project | ||
import org.gradle.api.publish.PublishingExtension | ||
import org.gradle.api.publish.maven.MavenPublication | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.create | ||
import org.gradle.kotlin.dsl.get | ||
import org.gradle.plugins.signing.SigningExtension | ||
|
||
private val isSnapshot: Boolean | ||
get() = Constants.VERSION_NAME.endsWith("SNAPSHOT") | ||
|
||
private fun Project.configureRepositories() { | ||
configure<PublishingExtension> { | ||
publications { | ||
repositories { | ||
maven { | ||
val releasesRepoUrl = | ||
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" | ||
val snapshotsRepoUrl = | ||
"https://s01.oss.sonatype.org/content/repositories/snapshots/" | ||
url = | ||
uri(if (isSnapshot) snapshotsRepoUrl else releasesRepoUrl) | ||
credentials { | ||
username = getProperties("OSSRH_USERNAME") | ||
password = getProperties("OSSRH_PASSWORD") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private val mavenPublicationName = "maven" | ||
|
||
private fun Project.configureMavenPublication( | ||
publishId: String, | ||
publishName: String, | ||
publishDescription: String, | ||
) { | ||
configure<PublishingExtension> { | ||
publications { | ||
create<MavenPublication>(mavenPublicationName) { | ||
groupId = Constants.GROUP_ID | ||
artifactId = publishId | ||
version = Constants.VERSION_NAME | ||
|
||
afterEvaluate { | ||
from(components["release"]) | ||
} | ||
|
||
pom { | ||
val pomURL = "https://github.com/virtusize/integration_android" | ||
name.set(publishName) | ||
packaging = "aar" | ||
description.set(publishDescription) | ||
url.set(pomURL) | ||
|
||
licenses { | ||
license { | ||
name.set("The MIT License") | ||
url.set("https://raw.githubusercontent.com/virtusize/integration_android/master/LICENSE") | ||
distribution.set("repo") | ||
} | ||
} | ||
|
||
developers { | ||
developer { | ||
id.set("virtusize") | ||
name.set("Virtusize") | ||
} | ||
} | ||
|
||
scm { | ||
connection.set("scm:git@github.com/virtusize/integration_android.git") | ||
developerConnection.set("scm:git@github.com/virtusize/integration_android.git") | ||
url.set(pomURL) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun Project.configureSigning(publication: PublishingExtension) { | ||
configure<SigningExtension> { | ||
val areSigningCredentialsProvided = | ||
getProperties("GPG_KEY_ID") != null && | ||
getProperties("GPG_KEY") != null && | ||
getProperties("GPG_KEY_PASSWORD") != null | ||
isRequired = !isSnapshot && areSigningCredentialsProvided | ||
if (isRequired) { | ||
useInMemoryPgpKeys( | ||
getProperties("GPG_KEY_ID"), | ||
getProperties("GPG_KEY"), | ||
getProperties("GPG_KEY_PASSWORD"), | ||
) | ||
} | ||
sign(publication.publications[mavenPublicationName]) | ||
} | ||
} | ||
|
||
fun Project.publish( | ||
publishId: String, | ||
publishName: String, | ||
publishDescription: String, | ||
publication: PublishingExtension, | ||
) { | ||
configureRepositories() | ||
configureMavenPublication(publishId, publishName, publishDescription) | ||
configureSigning(publication) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
GROUP_ID=com.virtusize.android | ||
# Update VERSION_NAME when publishing a new release | ||
VERSION_NAME=2.5.5 | ||
|
||
POM_URL=https://github.com/virtusize/integration_android | ||
|
||
# Project-wide Gradle settings. | ||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
org.gradle.jvmargs=-Xmx1536m | ||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 | ||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. For more details, visit | ||
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects | ||
# org.gradle.parallel=true | ||
# AndroidX package structure to make it clearer which packages are bundled with the | ||
# Android operating system, and which are packaged with your app's APK | ||
# https://developer.android.com/topic/libraries/support-library/androidx-rn | ||
android.useAndroidX=true | ||
# Kotlin code style for this project: "official" or "obsolete": | ||
kotlin.code.style=official | ||
# Enable AndroidX | ||
android.enableJetifier=true | ||
android.useAndroidX=true | ||
android.defaults.buildfeatures.buildconfig=true | ||
# Enables namespacing of each library's R class so that its R class includes only the | ||
# resources declared in the library itself and none from the library's dependencies, | ||
# thereby reducing the size of the R class for that library | ||
android.nonTransitiveRClass=true |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.