Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NSDK-190] Migrate Build Configuration from Groovy to Kotlin #102

Merged
merged 19 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
distribution: 'adopt'
cache: gradle
- name: Deploy to OSSRH and publish to MavenCentral
run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
run: ./gradlew publishMavenPublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
710 changes: 359 additions & 351 deletions README-JP.md
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated README-JP.md

Large diffs are not rendered by default.

664 changes: 334 additions & 330 deletions README.md

Large diffs are not rendered by default.

67 changes: 0 additions & 67 deletions build.gradle

This file was deleted.

25 changes: 25 additions & 0 deletions build.gradle.kts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build.gradle to build.gradle.kts

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")
}
}
}
7 changes: 7 additions & 0 deletions buildSrc/build.gradle.kts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildSrc for build scripts

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common constants for build.gradle.kts files

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"
}
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)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reused the code to publish the SDK (virtusize and virtusize-core)

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)
}
30 changes: 19 additions & 11 deletions gradle.properties
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
90 changes: 0 additions & 90 deletions gradle/deploy.gradle

This file was deleted.

8 changes: 0 additions & 8 deletions gradle/githooks.gradle

This file was deleted.

Loading
Loading