Skip to content

Commit 2982fa1

Browse files
committed
Update: support publishing artifacts to local maven repo, users can easily host libs
1 parent bbeba0b commit 2982fa1

File tree

6 files changed

+140
-10
lines changed

6 files changed

+140
-10
lines changed

.vscode/tasks.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,23 @@
223223
},
224224
"group": "build",
225225
"problemMatcher": "$gcc"
226+
},
227+
{
228+
"label": "[Release] Publish AAR To Maven Local",
229+
"type": "shell",
230+
"command": "bash",
231+
"args": [
232+
"vscode_tasks.sh",
233+
"--publish",
234+
],
235+
"options": {
236+
"cwd": "${workspaceFolder}"
237+
},
238+
"group": "build",
239+
"problemMatcher": "$gcc",
240+
"dependsOn": [
241+
"[Release] Enable CMake And Build Project With CMake"
242+
]
226243
}
227244
]
228245
}

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ ext {
2626
buildToolsVersion: '30.0.3',
2727
minSdkVersion : 16,
2828
targetSdkVersion : 25, // higher target version needs more storage permission request.
29-
versionCode : 1,
30-
versionName : "1.0.0",
29+
versionCode : 2,
30+
versionName : "3.0.0",
3131
applicationId : "org.wysaid.cgeDemo",
32-
appcompatX : "1.2.0"
32+
appcompatX : "1.2.0",
33+
ndkVersion : "23.1.7779620",
34+
cmakeVersion : "3.22.1",
3335
]
3436
}

cgeDemo/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ android {
1515
buildToolsVersion rootProject.ext.android.buildToolsVersion
1616

1717
if (usingCMakeCompile()) {
18-
ndkVersion "23.1.7779620"
18+
ndkVersion rootProject.ext.android.ndkVersion
1919
}
2020

2121
defaultConfig {

library/build.gradle

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ def disableVideoModule() {
1414
return gradle.ext != null && gradle.ext.has("disableVideoModule") && gradle.ext.disableVideoModule;
1515
}
1616

17+
def deployArtifacts() {
18+
return gradle.ext != null && gradle.ext.has("deployArtifacts") && gradle.ext.deployArtifacts;
19+
}
20+
1721
android {
1822
compileSdkVersion rootProject.ext.android.compileSdkVersion
1923
buildToolsVersion rootProject.ext.android.buildToolsVersion
2024

2125
if (usingCMakeCompile()) {
22-
ndkVersion "23.1.7779620"
26+
ndkVersion rootProject.ext.android.ndkVersion
2327
}
2428

2529
defaultConfig {
@@ -77,7 +81,7 @@ android {
7781
externalNativeBuild {
7882
cmake {
7983
path 'src/main/jni/CMakeLists.txt'
80-
version "3.22.1"
84+
version rootProject.ext.android.cmakeVersion
8185
}
8286
}
8387
}
@@ -101,10 +105,94 @@ android {
101105
sourceCompatibility JavaVersion.VERSION_1_8
102106
targetCompatibility JavaVersion.VERSION_1_8
103107
}
104-
namespace 'org.wysaid.library'
108+
109+
namespace = 'org.wysaid.library'
105110
}
106111

107112
dependencies {
108113
implementation fileTree(dir: 'libs', include: ['*.jar'])
109114
implementation 'androidx.appcompat:appcompat:' + rootProject.ext.android.appcompatX
110115
}
116+
117+
if (deployArtifacts()) {
118+
apply plugin: 'maven-publish'
119+
120+
def siteUrl = 'https://github.com/wysaid/android-gpuimage-plus'
121+
def gitUrl = 'https://github.com/wysaid/android-gpuimage-plus.git'
122+
group = "org.wysaid"
123+
version = rootProject.ext.android.versionName
124+
125+
publishing {
126+
publications {
127+
release(MavenPublication) {
128+
artifactId = 'gpuimage-plus'
129+
groupId = 'org.wysaid'
130+
version = rootProject.ext.android.versionName
131+
132+
afterEvaluate {
133+
from components.release
134+
// artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
135+
}
136+
137+
pom {
138+
name = 'gpuimage-plus'
139+
description = 'A C++ & Java library for Image/Camera/Video filters.'
140+
url = siteUrl
141+
142+
developers {
143+
developer {
144+
id = 'wysaid'
145+
name = 'Wang Yang'
146+
email = 'wysaid@gmail.com'
147+
}
148+
}
149+
150+
scm {
151+
connection = gitUrl
152+
developerConnection = gitUrl
153+
url = siteUrl
154+
}
155+
156+
licenses {
157+
license {
158+
name = 'The MIT License'
159+
url = 'https://github.com/wysaid/android-gpuimage-plus/blob/master/LICENSE'
160+
}
161+
}
162+
}
163+
}
164+
}
165+
repositories {
166+
maven {
167+
name = "local_repo"
168+
url = gradle.ext.localRepoDir
169+
// credentials {
170+
// username = gradle.ext.repoUsername
171+
// password = gradle.ext.repoPassword
172+
// }
173+
}
174+
}
175+
}
176+
177+
task sourcesJar(type: Jar) {
178+
from android.sourceSets.main.java.srcDirs
179+
classifier = 'sources'
180+
}
181+
182+
task javadoc(type: Javadoc) {
183+
source = android.sourceSets.main.java.srcDirs
184+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
185+
}
186+
187+
task javadocJar(type: Jar, dependsOn: javadoc) {
188+
classifier = 'javadoc'
189+
from javadoc.destinationDir
190+
}
191+
192+
artifacts {
193+
archives javadocJar
194+
archives sourcesJar
195+
}
196+
197+
}
198+

settings.gradle

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,35 @@ if (properties.getProperty('usingCMakeCompileDebug', null) == null) {
1212
pFile.append('\nusingCMakeCompileDebug=false\n')
1313
}
1414

15-
1615
/// if disableVideoModule is true, the recording functions is disabled,
1716
/// and ffmpeg will not be used.
1817
if (properties.getProperty('disableVideoModule', null) == null) {
1918
pFile.append('\ndisableVideoModule=false\n')
2019
}
2120

21+
if (properties.getProperty('deployArtifacts', null) == null) {
22+
pFile.append('\ndeployArtifacts=false\n')
23+
}
24+
25+
def homeDir = System.getenv('HOME')
26+
def mavenLocalDir = "maven_local_repo"
27+
28+
if (homeDir != null && !homeDir.isEmpty()) {
29+
mavenLocalDir = homeDir + '/' + mavenLocalDir
30+
}
31+
32+
/// if deployArtifacts is true, the deploy mode is on.
33+
if (properties.getProperty('localRepoDir', null) == null) {
34+
35+
pFile.append('\nlocalRepoDir=' + mavenLocalDir + '\n')
36+
}
37+
2238
if (gradle.ext == null) {
2339
gradle.ext = {}
2440
}
2541

2642
gradle.ext.usingCMakeCompile = properties.getProperty("usingCMakeCompile", "") == "true"
2743
gradle.ext.usingCMakeCompileDebug = properties.getProperty("usingCMakeCompileDebug", "") == "true"
28-
gradle.ext.disableVideoModule = properties.getProperty("disableVideoModule", "") == "true"
44+
gradle.ext.disableVideoModule = properties.getProperty("disableVideoModule", "") == "true"
45+
gradle.ext.deployArtifacts = properties.getProperty("deployArtifacts", "") == "true"
46+
gradle.ext.localRepoDir = properties.getProperty("localRepoDir", mavenLocalDir)

vscode_tasks.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ while [[ $# > 0 ]]; do
170170
changeProperty "local.properties" '^disableVideoModule=' 's/disableVideoModule=.*/disableVideoModule=true/' 'disableVideoModule=true'
171171
shift # past argument
172172
;;
173-
173+
--publish)
174+
echo "publish"
175+
changeProperty "local.properties" '^deployArtifacts=' 's/deployArtifacts=.*/deployArtifacts=true/' 'disableVideoModule=true'
176+
./gradlew assembleRelease publish
177+
shift
178+
;;
174179
*)
175180
echo "Invalid argument $PARSE_KEY..."
176181
exit 1

0 commit comments

Comments
 (0)