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

chore: prepare module for maven release #88

Merged
merged 20 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
80f7c1a
chore(android): add ACCESS_NETWORK_STATE permission
1abhishekpandey Dec 13, 2024
69c8340
chore(gradle): add publishing.gradle.kts
1abhishekpandey Dec 13, 2024
e0684f6
chore(core): prepare core for publishing
1abhishekpandey Dec 13, 2024
784367c
chore(android): prepare android for publishing
1abhishekpandey Dec 13, 2024
1c38fe5
chore: add LICENSE.md
1abhishekpandey Dec 13, 2024
5270217
chore: configure nexus plugin
1abhishekpandey Dec 13, 2024
ab139b3
chore: add version details in pom.xml
1abhishekpandey Dec 13, 2024
04e8f29
chore(gradle): remove stale line
1abhishekpandey Dec 13, 2024
8d53cb1
chore: add version code in buildSrc
1abhishekpandey Dec 13, 2024
1b88e1e
chore: fix: remove unnecessary quotes around VERSION_NAME
1abhishekpandey Dec 13, 2024
f4164ca
refactor: use VERSION_NAME as a SSOT
1abhishekpandey Dec 13, 2024
1d8c5c3
chore(android): add INTERNET permission
1abhishekpandey Dec 13, 2024
bd9528d
Merge remote-tracking branch 'origin/develop.poc' into feat/sdk-2730-…
1abhishekpandey Dec 13, 2024
67dcb0c
chore: remove commented code
1abhishekpandey Dec 13, 2024
729dddf
Merge remote-tracking branch 'origin/develop.poc' into feat/sdk-2730-…
1abhishekpandey Dec 16, 2024
e500871
refactor: remove pom configuration from gradle.properties
1abhishekpandey Dec 17, 2024
4254392
refactor: pom configuration to BuildConfig
1abhishekpandey Dec 17, 2024
e805e5e
refactor: module specific to BuildConfig
1abhishekpandey Dec 17, 2024
59c58e8
chore: reformat code
1abhishekpandey Dec 17, 2024
3c96394
refactor: use constant
1abhishekpandey Dec 17, 2024
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
44 changes: 44 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
### Elastic License 2.0 (ELv2) ###

## Acceptance ##
By using the software, you agree to all of the terms and conditions below.

## Copyright License ##
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below

## Limitations ##
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.

You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.

You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.

## Patents ##
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.

## Notices ##
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.

If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.

## No Other Rights ##
These terms do not imply any licenses other than those expressly granted in these terms.

## Termination ##
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.

## No Liability ##
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.

## Definitions ##
The *licensor* is the entity offering these terms, and the *software* is the software the licensor makes available under these terms, including any portion of it.

*you* refers to the individual or entity agreeing to these terms.

*your company* is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. *control* means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.

*your licenses* are all the licenses granted to you for the software under these terms.

*use* means anything you do with the software requiring one of your licenses.

*trademark* means trademarks, service marks, and similar rights.
37 changes: 36 additions & 1 deletion android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")

buildConfigField("String", "VERSION_NAME", RudderStackBuildConfig.Version.VERSION_NAME)
buildConfigField("String", "VERSION_NAME", "\"${RudderStackBuildConfig.Version.VERSION_NAME}\"")
buildConfigField("int", "VERSION_CODE", RudderStackBuildConfig.Version.VERSION_CODE)
}

Expand All @@ -63,6 +63,39 @@ android {
}
}

// For generating SourcesJar and JavadocJar
tasks {
val sourceFiles = (android.sourceSets["main"].kotlin as com.android.build.gradle.internal.api.DefaultAndroidSourceDirectorySet).srcDirs

register<Javadoc>("withJavadoc") {
isFailOnError = false

setSource(sourceFiles)

// add Android runtime classpath
android.bootClasspath.forEach { classpath += project.fileTree(it) }

// add classpath for all dependencies
android.libraryVariants.forEach { variant ->
variant.javaCompileProvider.get().classpath.files.forEach { file ->
classpath += project.fileTree(file)
}
}
}

register<Jar>("javadocJar") {
archiveClassifier.set("javadoc")
dependsOn(named("withJavadoc"))
val destination = named<Javadoc>("withJavadoc").get().destinationDir
from(destination)
}

register<Jar>("sourcesJar") {
archiveClassifier.set("sources")
from(sourceFiles)
}
}

dependencies {
//api
api(project(":core"))
Expand All @@ -85,3 +118,5 @@ dependencies {
testImplementation(libs.json.assert)
testImplementation(libs.navigation.runtime)
}

apply(from = rootProject.file("gradle/publishing/publishing.gradle.kts"))
4 changes: 3 additions & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" android:required="false" />
<uses-permission android:name="android.permission.INTERNET"/>

</manifest>
38 changes: 38 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,43 @@ plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.detekt) apply false
alias(libs.plugins.nexus)
}

fun getVersionName(): String {
return if (project.hasProperty("release")) {
RudderStackBuildConfig.Version.VERSION_NAME
} else {
"${RudderStackBuildConfig.Version.VERSION_NAME}-SNAPSHOT"
}
}

allprojects {
group = RudderStackBuildConfig.PackageName.PACKAGE_NAME
version = getVersionName()
}

tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}

nexusPublishing {
repositories {
sonatype {
if (System.getenv("NEXUS_USERNAME") == null || System.getenv("NEXUS_PASSWORD") == null || System.getenv("SONATYPE_STAGING_PROFILE_ID") == null) {
println("RudderStack: Error in fetching the Nexus environment variables.")
} else{
println("RudderStack: Nexus environment variables fetched successfully.")
}

username = System.getenv("NEXUS_USERNAME")
password = System.getenv("NEXUS_PASSWORD")
stagingProfileId = System.getenv("SONATYPE_STAGING_PROFILE_ID")

nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}

true // Needed to make the Suppress annotation work for the plugins block
40 changes: 39 additions & 1 deletion buildSrc/src/main/kotlin/RudderStackBuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object RudderStackBuildConfig {

object Version {

const val VERSION_NAME = "\"1.0.0\""
const val VERSION_NAME = "1.0.0"
const val VERSION_CODE = "1"
}

Expand All @@ -36,4 +36,42 @@ object RudderStackBuildConfig {
val VERSION_NAME = ""
val GROUP_NAME = ""
}

object POM {

const val NAME = "Kotlin-SDK-POC"
const val DESCRIPTION = "RudderStack\'s SDK for android"

const val URL = "https://github.com/rudderlabs/kotlin-sdk-poc"
const val SCM_URL = "https://github.com/rudderlabs/kotlin-sdk-poc/tree/main"
const val SCM_CONNECTION = "scm:git:git://github.com/rudderlabs/kotlin-sdk-poc.git"
const val SCM_DEV_CONNECTION = "scm:git:git://github.com:rudderlabs/kotlin-sdk-poc.git"

const val LICENCE_NAME = "Elastic License 2.0 (ELv2)"
const val LICENCE_URL = "http://opensource.org/licenses/MIT"
const val LICENCE_DIST = "repo"

const val DEVELOPER_ID = "Rudderstack"
const val DEVELOPER_NAME = "Rudderstack, Inc."
}

object Modules {
object Android : ModuleConfig {

override val artifactId = "android"
override val pomPackaging = "aar"
}

object Core : ModuleConfig {

override val artifactId = "core"
override val pomPackaging = "jar"
}
}
}

interface ModuleConfig {

val artifactId: String
val pomPackaging: String
}
22 changes: 21 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions.freeCompilerArgs.add("-opt-in=com.rudderstack.sdk.kotlin.core.internals.utils.InternalRudderApi")
}

// For generating SourcesJar and JavadocJar
tasks {
val sourcesJar by creating(Jar::class) {
dependsOn(JavaPlugin.CLASSES_TASK_NAME)
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}

val javadocJar by creating(Jar::class) {
archiveClassifier.set("javadoc")
}

artifacts {
add("archives", sourcesJar)
add("archives", javadocJar)
}
}

// Task to generate a Kotlin file with version constants
tasks.register("generateVersionConstants") {
val outputDir = layout.buildDirectory.dir("generated/source/version")
Expand All @@ -34,7 +52,7 @@ tasks.register("generateVersionConstants") {
package source.version

object VersionConstants {
const val VERSION_NAME = ${RudderStackBuildConfig.Version.VERSION_NAME}
const val VERSION_NAME = "${RudderStackBuildConfig.Version.VERSION_NAME}"
const val LIBRARY_PACKAGE_NAME = "${RudderStackBuildConfig.PackageName.PACKAGE_NAME}"
}
""".trimIndent()
Expand Down Expand Up @@ -79,3 +97,5 @@ dependencies {
testImplementation(libs.json.assert)
testImplementation(libs.kotlinx.coroutines.test)
}

apply(from = rootProject.file("gradle/publishing/publishing.gradle.kts"))
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ detekt = "1.23.6"
navigation = "2.8.4"
play-services-ads = "23.5.0"
ui = "1.7.5"
nexus = "2.0.0"

[libraries]
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity-compose" }
Expand Down Expand Up @@ -48,3 +49,4 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
nexus = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus" }
116 changes: 116 additions & 0 deletions gradle/publishing/publishing.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
apply(plugin = "maven-publish")
apply(plugin = "signing")

private val PLATFORM_ANDROID = "android"

fun getExtraString(name: String) = extra[name]?.toString()

// If not release build add SNAPSHOT suffix
fun getVersionName() =
if (hasProperty("release"))
RudderStackBuildConfig.Version.VERSION_NAME
else
RudderStackBuildConfig.Version.VERSION_NAME + "-SNAPSHOT"

fun getModuleDetails(): ModuleConfig =
if (project.name == PLATFORM_ANDROID) {
RudderStackBuildConfig.Modules.Android
} else {
RudderStackBuildConfig.Modules.Core
}

configure<PublishingExtension> {
publications {
register<MavenPublication>("release") {
groupId = RudderStackBuildConfig.PackageName.PACKAGE_NAME
artifactId = getModuleDetails().artifactId
version = getVersionName()

println("RudderStack: Publishing following library to Maven Central: $groupId:$artifactId:$version")

// Add the `aar` or `jar` file to the artifacts
if (project.name == PLATFORM_ANDROID) {
artifact("$buildDir/outputs/aar/${project.name}-release.aar") {
builtBy(tasks.getByName("assemble"))
}
} else {
artifact("$buildDir/libs/${project.name}-${version}.jar") {
builtBy(tasks.getByName("assemble"))
}
}

// Add sources and javadoc jars
artifact(tasks.getByName("javadocJar"))
artifact(tasks.getByName("sourcesJar"))

// Add pom configuration
pom {
name.set(RudderStackBuildConfig.POM.NAME)
packaging = getModuleDetails().pomPackaging
description.set(RudderStackBuildConfig.POM.DESCRIPTION)
url.set(RudderStackBuildConfig.POM.URL)

licenses {
license {
name.set(RudderStackBuildConfig.POM.LICENCE_NAME)
url.set(RudderStackBuildConfig.POM.LICENCE_URL)
distribution.set(RudderStackBuildConfig.POM.LICENCE_DIST)
}
}

developers {
developer {
id.set(RudderStackBuildConfig.POM.DEVELOPER_ID)
name.set(RudderStackBuildConfig.POM.DEVELOPER_NAME)
}
}

scm {
url.set(RudderStackBuildConfig.POM.SCM_URL)
connection.set(RudderStackBuildConfig.POM.SCM_CONNECTION)
developerConnection.set(RudderStackBuildConfig.POM.SCM_DEV_CONNECTION)
}

// To include the transitive dependencies upon which the library depends
withXml {
val dependenciesNode = asNode().appendNode("dependencies")

fun addDependency(dep: Dependency, scope: String) {
if (dep.group == null || dep.name == "unspecified" || dep.version == null) return
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", dep.group)
dependencyNode.appendNode("artifactId", dep.name)
dependencyNode.appendNode("version", dep.version)
dependencyNode.appendNode("scope", scope)
}

configurations.findByName("api")?.dependencies?.forEach { dep ->
addDependency(dep, "compile")
}

configurations.findByName("implementation")?.dependencies?.forEach { dep ->
addDependency(dep, "runtime")
}
}
}
}
}
}

// Signing configuration
plugins.withType<SigningPlugin>().configureEach {
extensions.configure<SigningExtension> {
}
}

tasks.getByName("publish") {
dependsOn("build")
}

tasks.getByName("publishToMavenLocal") {
dependsOn("build")
}

tasks.getByName("publishToSonatype") {
dependsOn("publish")
}
Loading