From c7ae2d2d6b2f3c7436aed0d557a0bea067b39bd8 Mon Sep 17 00:00:00 2001 From: Jintin Date: Wed, 18 Jan 2023 00:07:28 +0800 Subject: [PATCH] Add maven script --- build.gradle | 17 ++++++++++++ lib/build.gradle | 12 ++++++++- lib/publish.gradle | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 lib/publish.gradle diff --git a/build.gradle b/build.gradle index dee89b5..ab1dc3b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. + buildscript { ext.kotlin_version = "1.5.21" repositories { @@ -13,6 +14,9 @@ buildscript { // in the individual module build.gradle files } } +plugins { + id 'io.github.gradle-nexus.publish-plugin' version('1.1.0') +} allprojects { repositories { @@ -24,4 +28,17 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir +} + +// Publish to Maven Central +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + username = System.getenv("OSS_USERNAME") + password = System.getenv("OSS_PASSWORD") + stagingProfileId = System.getenv("OSS_STAGING_PROFILE_ID") + } + } } \ No newline at end of file diff --git a/lib/build.gradle b/lib/build.gradle index 364be19..fddab0f 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -43,4 +43,14 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' -} \ No newline at end of file +} + +ext { + GROUP_ID = "io.github.jintin" // your project id registered in Sonatype + ARTIFACT_ID = "BindingExtension" // name of your library + VERSION = "1.0.0" + SITE_URL = 'https://github.com/Jintin/BindingExtension' + GIT_URL = 'https://github.com/Jintin/BindingExtension.git' +} + +apply from: 'publish.gradle' \ No newline at end of file diff --git a/lib/publish.gradle b/lib/publish.gradle new file mode 100644 index 0000000..6a41fcc --- /dev/null +++ b/lib/publish.gradle @@ -0,0 +1,67 @@ +apply plugin: 'maven-publish' +apply plugin: 'signing' + +// If you want to publish your sources as well +task androidSourcesJar(type: Jar) { + archiveClassifier.set('sources') + from android.sourceSets.main.java.srcDirs + from android.sourceSets.main.kotlin.srcDirs +} + +artifacts { + archives androidSourcesJar +} + +group = GROUP_ID +version = VERSION + +afterEvaluate { + publishing { + publications { + release(MavenPublication) { + + groupId GROUP_ID + artifactId ARTIFACT_ID + version VERSION + + from components.release + artifact androidSourcesJar + + pom { + name = ARTIFACT_ID + description = 'Android ViewBinding extension to provide simpler usage in Activity, Fragment and ViewHolder.' + url = SITE_URL + licenses { + // Your licensing information + license { + name = 'The Apache Software License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = 'Jintin' + name = 'Tim Lin' + email = 'jintin.lin1018@gmail.com' + } + // More developers if any... + } + + scm { + connection = GIT_URL + developerConnection = GIT_URL + url = SITE_URL + } + } + } + } + } +} + +signing { + useInMemoryPgpKeys( + System.getenv("OSS_SIGNING_KEY"), + System.getenv("OSS_SIGNING_PASSWORD"), + ) + sign publishing.publications +} \ No newline at end of file