-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
25603af
03a2db5
ed48d4a
532a09b
b53618c
094081b
1ac0687
d90695a
f6632d5
df928fd
cf002d6
f95815c
9557c93
5e8ee40
6730cf4
9df12f2
558d5c6
d9b25d5
8064d38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
} | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} |
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.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated README-JP.md