From 714d4cd4df704316e636151b67ed958f3eb9cbba Mon Sep 17 00:00:00 2001 From: jackChen Date: Mon, 13 Sep 2021 17:36:54 +0800 Subject: [PATCH] [build] publish lib to maven repo --- README.md | 13 +++++++++++++ build.gradle | 4 ++++ gradle.properties | 6 +++++- scripts/publish-module.gradle | 36 +++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 scripts/publish-module.gradle diff --git a/README.md b/README.md index bda2b72f..7df3cb33 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,16 @@ dependencies { implementation 'com.github.beatjs:react-android:0.63.4.+' } ``` + + +### publish lib to maven repo +1. create `local.properties` file to project root dir. +```properties +OSS_USERNAME={username} +OSS_PASSWORD={password} +OSS_REPOSITORY_URL={repo_url} +``` + +2. specify `GROUP_ID` , `VERSION_NAME` in `gradle.properties` + +3. exec gradle cmd `gradle uploadArchives` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3157ba7e..c0dcb51e 100644 --- a/build.gradle +++ b/build.gradle @@ -18,4 +18,8 @@ allprojects { jcenter() maven { url 'https://jitpack.io' } } +} + +subprojects { + apply from:"$rootDir/scripts/publish-module.gradle" } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 7f9f4548..7fe0c77d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,4 +17,8 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true -android.useDeprecatedNdk=true \ No newline at end of file +android.useDeprecatedNdk=true + + +VERSION_NAME=0.63.4.1 +GROUP_ID=com.github.beatjs \ No newline at end of file diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle new file mode 100644 index 00000000..c69b2079 --- /dev/null +++ b/scripts/publish-module.gradle @@ -0,0 +1,36 @@ +apply plugin: "maven" + +ext["ossrhUsername"] = '' +ext["ossrhPassword"] = '' + +File secretPropsFile = project.rootProject.file('local.properties') +if (secretPropsFile.exists()) { + Properties p = new Properties() + new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) } + p.each { name, value -> + ext[name] = value + } +} else { + ext["OSS_USERNAME"] = System.getenv('OSS_USERNAME') + ext["OSS_PASSWORD"] = System.getenv('OSS_PASSWORD') +} + + +logger.quiet("project:$project.name GROUP_ID:$GROUP_ID") +logger.quiet(">>> OSS_REPOSITORY_URL:$OSS_REPOSITORY_URL") + +uploadArchives { + repositories { + mavenDeployer { + repository(url: OSS_REPOSITORY_URL) { + authentication(userName: OSS_USERNAME, password: OSS_PASSWORD) + } + pom.project { + artifactId project.name + version VERSION_NAME + groupId GROUP_ID + packaging 'aar' + } + } + } +} \ No newline at end of file