diff --git a/build.gradle b/build.gradle index 86e00d2..676df05 100644 --- a/build.gradle +++ b/build.gradle @@ -1,29 +1,39 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { repositories { google() - jcenter() + mavenCentral() + maven { + url "https://plugins.gradle.org/m2/" + } } dependencies { - classpath 'com.android.tools.build:gradle:8.1.1' + classpath 'com.android.tools.build:gradle:7.3.1' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath 'io.github.gradle-nexus:publish-plugin:1.1.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } +apply plugin: 'io.github.gradle-nexus.publish-plugin' allprojects { repositories { google() - jcenter() + mavenCentral() maven { url 'https://jitpack.io' } } } +nexusPublishing { + repositories { + sonatype() + } +} + task clean(type: Delete) { delete rootProject.buildDir } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2c4d430..ecb96a7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip \ No newline at end of file +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index 8f56977..fd83086 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,6 +1,27 @@ apply plugin: 'com.android.library' +apply plugin: 'maven-publish' group='com.github.TutorialsAndroid' +ext { + PUBLISH_GROUP_ID = 'io.github.tutorialsandroid' + PUBLISH_VERSION = '9.0.0' + PUBLISH_ARTIFACT_ID = 'filepicker' + PUBLISH_DESCRIPTION = 'Android Library to select files/directories from Device Storage' + PUBLISH_URL = 'https://github.com/TutorialsAndroid/FilePicker' + PUBLISH_LICENSE_NAME = 'Apache License' + PUBLISH_LICENSE_URL = + 'https://github.com/TutorialsAndroid/FilePicker/blob/master/LICENSE' + PUBLISH_DEVELOPER_ID = 'tutorialsandroid' + PUBLISH_DEVELOPER_NAME = 'Akshay Masram' + PUBLISH_DEVELOPER_EMAIL = 'akshaysunilmasram@yahoo.com' + PUBLISH_SCM_CONNECTION = + 'scm:git:github.com/tutorialsandroid/filepicker.git' + PUBLISH_SCM_DEVELOPER_CONNECTION = + 'scm:git:ssh://github.com/tutorialsandroid/filepicker.git' + PUBLISH_SCM_URL = + 'https://github.com/tutorialsandroid/filepicker/tree/master' +} + android { compileSdk 34 @@ -15,7 +36,29 @@ android { } } namespace 'com.developer.filepicker' + + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } lint { abortOnError false } } + +publishing { + publications { + release(MavenPublication) { + groupId = PUBLISH_GROUP_ID + artifactId = PUBLISH_ARTIFACT_ID + version = PUBLISH_VERSION + + from components.findByName('release') + artifact("$buildDir/outputs/aar/library-release.aar") + } + } + + tasks.named('publishReleasePublicationToMavenLocal') { + dependsOn tasks.named('bundleReleaseAar') + } +} diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle new file mode 100644 index 0000000..f90a603 --- /dev/null +++ b/scripts/publish-module.gradle @@ -0,0 +1,77 @@ +apply plugin: 'maven-publish' +apply plugin: 'signing' + +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 + 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 { + artifact("$buildDir/libs/${project.getName()}-${version}.jar") + } + + artifact bundleReleaseAar + + // 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 +} diff --git a/scripts/publish-root.gradle b/scripts/publish-root.gradle new file mode 100644 index 0000000..caec3a3 --- /dev/null +++ b/scripts/publish-root.gradle @@ -0,0 +1,36 @@ +// Create variables with empty default values +ext["signing.keyId"] = '' +ext["signing.password"] = '' +ext["signing.secretKeyRingFile"] = '' +ext["ossrhUsername"] = '' +ext["ossrhPassword"] = '' +ext["sonatypeStagingProfileId"] = '' + +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/")) + } + } +}