Skip to content

Commit

Permalink
add code and changes for publish library on maven central.
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarsmartsense committed Jun 11, 2024
1 parent 993a8ee commit 0898002
Show file tree
Hide file tree
Showing 32 changed files with 238 additions and 120 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
*.iml
.gradle
.idea
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
./idea/
/build
/captures
.externalNativeBuild
Expand Down
12 changes: 3 additions & 9 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ plugins {
}

android {
namespace = "com.ss.smartstorage"
namespace = "com.ss.smartstoragedemo"
compileSdk = 34

defaultConfig {
applicationId = "com.ss.smartstorage"
applicationId = "com.ss.smartstoragedemo"
minSdk = 23
targetSdk = 34
versionCode = 1
Expand Down Expand Up @@ -60,7 +60,7 @@ dependencies {
implementation(libs.androidx.material3)
implementation(libs.coil.compose)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(project(":smart-storage"))
implementation(project(":smartStorage"))
implementation(libs.androidx.appcompat)
implementation(libs.androidx.documentfile)
testImplementation(libs.junit)
Expand All @@ -70,10 +70,4 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)



project(":smart-storage")


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ss.smartstorage
package com.ss.smartstoragedemo

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ss.smartstorage
package com.ss.smartstoragedemo

import android.content.Context
import android.os.Handler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ss.smartstorage
package com.ss.smartstoragedemo

import android.annotation.SuppressLint
import android.os.Bundle
Expand All @@ -9,9 +9,9 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.ss.smart_storage.OutputListener
import com.ss.smart_storage.SmartStorage
import com.ss.smartstorage.ui.theme.SmartStorageTheme
import com.ss.smartstorage.OutputListener
import com.ss.smartstorage.SmartStorage
import com.ss.smartstoragedemo.ui.theme.SmartStorageTheme

class MainActivity : ComponentActivity(), OutputListener {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ss.smartstorage
package com.ss.smartstoragedemo

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -35,8 +35,8 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.ss.smart_storage.util.SmartDirectory
import com.ss.smart_storage.util.SmartFileType
import com.ss.smartstorage.util.SmartDirectory
import com.ss.smartstorage.util.SmartFileType
import kotlinx.coroutines.launch


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ss.smartstorage
package com.ss.smartstoragedemo

import androidx.compose.runtime.mutableIntStateOf
import androidx.lifecycle.ViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ss.smartstorage.ui.theme
package com.ss.smartstoragedemo.ui.theme

import androidx.compose.ui.graphics.Color

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.ss.smartstorage.ui.theme
package com.ss.smartstoragedemo.ui.theme

import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ss.smartstorage.ui.theme
package com.ss.smartstoragedemo.ui.theme

import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ss.smartstorage
package com.ss.smartstoragedemo

import org.junit.Test

Expand Down
11 changes: 11 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@ plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.nexusPublish) apply true
}

apply {
from("${rootDir}/scripts/publish-root.gradle")
}

tasks {
register("clean", Delete::class) {
delete(rootProject.buildDir)
}
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ appcompat = "1.6.1"
lifecycleViewmodelCompose = "2.7.0"
material = "1.11.0"
documentfile = "1.0.1"
nexusPublish = "1.1.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand All @@ -39,4 +40,5 @@ androidx-documentfile = { group = "androidx.documentfile", name = "documentfile"
androidApplication = { id = "com.android.application", version.ref = "agp" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }
nexusPublish = {id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPublish"}

90 changes: 90 additions & 0 deletions scripts/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

tasks.register('androidSourcesJar', Jar) {
archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) {
from android.sourceSets.main.kotlin.srcDirs
from android.sourceSets.main.java.srcDirs
} else {
from sourceSets.main.java.srcDirs
from sourceSets.main.kotlin.srcDirs
}
}
//
//task androidSourcesJar(type: Jar) {
// archiveClassifier.set('sources')
// if (project.plugins.findPlugin("com.android.library")) {
// from android.sourceSets.main.java.srcDirs
// } else {
// from sourceSets.main.java.srcDirs
// }
//}

artifacts {
archives androidSourcesJar
}

group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
// The coordinates of the library, being set from variables that
// we'll set up later
tasks.named("generateMetadataFileForReleasePublication").configure { dependsOn("androidSourcesJar") }
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION

// Two artifacts, the `aar` (or `jar`) and the sources
if (project.plugins.findPlugin("com.android.library")) {
from components.release
} else {
from components.java
// artifact("$buildDir/libs/${project.getName()}-${version}.jar")
}

// artifact androidSourcesJar

// Mostly self-explanatory metadata
pom {
name = PUBLISH_ARTIFACT_ID
description = PUBLISH_DESCRIPTION
url = PUBLISH_URL
licenses {
license {
name = PUBLISH_LICENSE_NAME
url = PUBLISH_LICENSE_URL
}
}
developers {
developer {
id = PUBLISH_DEVELOPER_ID
name = PUBLISH_DEVELOPER_NAME
email = PUBLISH_DEVELOPER_EMAIL
}
}

// Version control info - if you're using GitHub, follow the
// format as seen here
scm {
connection = PUBLISH_SCM_CONNECTION
developerConnection = PUBLISH_SCM_DEVELOPER_CONNECTION
url = PUBLISH_SCM_URL
}
}
}
}
}
}

ext["signing.keyId"] = rootProject.ext["signing.keyId"]
ext["signing.password"] = rootProject.ext["signing.password"]
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]

signing {
sign publishing.publications
}
37 changes: 37 additions & 0 deletions scripts/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Create variables with empty default values

ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.secretKeyRingFile"] = ''

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
// Use system environment variables
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
}

// Set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ dependencyResolutionManagement {

rootProject.name = "SmartStorage"
include(":app")
include(":smart-storage")
include(":smartStorage")
38 changes: 0 additions & 38 deletions smart-storage/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 0898002

Please sign in to comment.