1
+ apply plugin : ' maven-publish'
2
+ apply plugin : ' signing'
3
+
4
+ group = " io.github.yvescheung" // Maven Group ID for the artifact
5
+ version = libraryVersion
6
+ final String developerId = ' YvesCheung'
7
+ final String developerName = ' YvesCheung'
8
+ final String developerEmail = ' 975135274@qq.com'
9
+ final String licenseName = ' The Apache License, Version 2.0'
10
+ final String licenseUrl = ' http://www.apache.org/licenses/LICENSE-2.0'
11
+
12
+ if (project. hasProperty(" android" )) { // Android libraries
13
+ task sourcesJar(type : Jar ) {
14
+ classifier = ' sources'
15
+ getArchiveBaseName(). set(libraryName)
16
+ from android. sourceSets. main. java. srcDirs
17
+ }
18
+ task androidNativeJar(type : Jar ) {
19
+ classifier = ' so'
20
+ from(new File (buildDir, ' libs' ))
21
+ include(" **/*.so" )
22
+ }
23
+ ext. libraryOutputFile = " $buildDir /outputs/aar/${ project.getName()} -release.aar"
24
+ } else { // Java libraries
25
+ task sourcesJar(type : Jar , dependsOn : classes) {
26
+ classifier = ' sources'
27
+ getArchiveBaseName(). set(libraryName)
28
+ from sourceSets. main. allSource
29
+ }
30
+ ext. libraryOutputFile = " $buildDir /libs/${ project.getName()} -${ version} .jar"
31
+ }
32
+ println (" artifect: $libraryOutputFile " )
33
+
34
+ /**
35
+ * ossrhUsername
36
+ * ossrhPassword
37
+ * signing.keyId
38
+ * signing.password
39
+ * signing.secretKeyRingFile
40
+ * Variables defined in local.properties
41
+ */
42
+ Properties properties = new Properties ()
43
+ File localProperties = project. rootProject. file(' local.properties' )
44
+ if (localProperties. exists()) {
45
+ properties. load(localProperties. newDataInputStream())
46
+ }
47
+
48
+ afterEvaluate {
49
+ publishing {
50
+ if (properties[' ossrhUsername' ] != null ) {
51
+ repositories {
52
+ maven {
53
+ // You only need this if you want to publish snapshots, otherwise just set the URL
54
+ // to the release repo directly
55
+ url = version. endsWith(' SNAPSHOT' )
56
+ ? " https://s01.oss.sonatype.org/content/repositories/snapshots/"
57
+ : " https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
58
+
59
+ // The username and password we've fetched earlier
60
+ credentials {
61
+ username properties[' ossrhUsername' ]
62
+ password properties[' ossrhPassword' ]
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ publications {
69
+ MyPublication (MavenPublication ) {
70
+ from components. release
71
+ groupId group
72
+ artifactId libraryName
73
+ artifact sourcesJar
74
+ version libraryVersion
75
+ pom {
76
+ name = libraryName
77
+ description = libraryDescription
78
+ url = siteUrl
79
+
80
+ developers {
81
+ developer {
82
+ id = developerId
83
+ name = developerName
84
+ email = developerEmail
85
+ }
86
+ }
87
+
88
+ scm {
89
+ connection = gitUrl
90
+ developerConnection = gitUrl
91
+ url = siteUrl
92
+ }
93
+
94
+ licenses {
95
+ license {
96
+ name = licenseName
97
+ url = licenseUrl
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+ }
104
+
105
+ if (properties[' signing.keyId' ] != null ) {
106
+ ext[' signing.keyId' ] = properties[' signing.keyId' ]
107
+ ext[' signing.password' ] = properties[' signing.password' ]
108
+ ext[' signing.secretKeyRingFile' ] = properties[' signing.secretKeyRingFile' ]
109
+ signing {
110
+ sign publishing. publications
111
+ }
112
+ }
113
+ }
0 commit comments