@@ -29,70 +29,73 @@ if (secretPropsFile.exists()) {
29
29
println " No props file, loading env vars"
30
30
}
31
31
32
+ def configurePublication = { MavenPublication publication ->
33
+ groupId PUBLISH_GROUP_ID
34
+ artifactId PUBLISH_ARTIFACT_ID
35
+ version PUBLISH_VERSION
32
36
33
- publishing {
34
- publications {
35
- release(MavenPublication ) {
36
- groupId PUBLISH_GROUP_ID
37
- artifactId PUBLISH_ARTIFACT_ID
38
- version PUBLISH_VERSION
37
+ def uploadJar = " mavenJava" == publication. name
38
+ if (uploadJar) {
39
+ from components. java
40
+ artifact sourcesJar
41
+ artifact javadocJar
42
+ } else {
43
+ artifact tasks. getByName(" bundleReleaseAar" )
44
+ artifact androidSourcesJar
45
+ }
39
46
40
- if (isAar) {
41
- afterEvaluate { artifact(tasks. getByName(" bundleReleaseAar" )) }
42
- artifact androidSourcesJar
43
- } else {
44
- components. java
45
- artifact sourcesJar
46
- artifact javadocJar
47
+ pom {
48
+ name = PUBLISH_ARTIFACT_ID
49
+ description = ' XRouter-Android'
50
+ url = ' https://github.com/wangshuwen1107/XRouter-Android.git'
51
+ licenses {
52
+ license {
53
+ // 协议类型,一般默认Apache License2.0的话不用改:
54
+ name = ' The Apache License, Version 2.0'
55
+ url = ' http://www.apache.org/licenses/LICENSE-2.0.txt'
47
56
}
48
-
49
- pom {
50
- name = PUBLISH_ARTIFACT_ID
51
- description = ' XRouter-Android'
52
- url = ' https://github.com/wangshuwen1107/XRouter-Android.git'
53
- licenses {
54
- license {
55
- // 协议类型,一般默认Apache License2.0的话不用改:
56
- name = ' The Apache License, Version 2.0'
57
- url = ' http://www.apache.org/licenses/LICENSE-2.0.txt'
58
- }
59
- }
60
- developers {
61
- developer {
62
- id = ' wangshuwen1107'
63
- name = ' wangshuwen1107'
64
- email = ' wnwn7375@outlook.com'
65
- }
66
- }
67
- // Version control info, if you're using GitHub, follow the format as seen here
68
- scm {
69
- connection = ' scm:git:github.com/wangshuwen1107/XRouter-Android.git'
70
- developerConnection = ' scm:git:ssh://github.com/wangshuwen1107/XRouter-Android.git'
71
- url = ' https://github.com/wangshuwen1107/XRouter-Android.git/master'
72
- }
73
- // A slightly hacky fix so that your POM will include any transitive dependencies
74
- // that your library builds upon
75
- withXml {
76
- def dependenciesNode = asNode(). appendNode(' dependencies' )
77
- project. configurations. implementation. allDependencies. each {
78
- if (null != it. group && null != it. name && null != it. version) {
79
- def dependencyNode = dependenciesNode. appendNode(' dependency' )
80
- dependencyNode. appendNode(' groupId' , it. group)
81
- dependencyNode. appendNode(' artifactId' , it. name)
82
- dependencyNode. appendNode(' version' , it. version)
83
- }
57
+ }
58
+ developers {
59
+ developer {
60
+ id = ' wangshuwen1107'
61
+ name = ' wangshuwen1107'
62
+ email = ' wnwn7375@outlook.com'
63
+ }
64
+ }
65
+ scm {
66
+ connection = ' scm:git:github.com/wangshuwen1107/XRouter-Android.git'
67
+ developerConnection = ' scm:git:ssh://github.com/wangshuwen1107/XRouter-Android.git'
68
+ url = ' https://github.com/wangshuwen1107/XRouter-Android.git/master'
69
+ }
70
+ withXml {
71
+ if (! uploadJar) {
72
+ def dependenciesNode = asNode(). appendNode(' dependencies' )
73
+ project. configurations. implementation. allDependencies. each {
74
+ if (null != it. group && null != it. name && null != it. version) {
75
+ def dependencyNode = dependenciesNode. appendNode(' dependency' )
76
+ dependencyNode. appendNode(' groupId' , it. group)
77
+ dependencyNode. appendNode(' artifactId' , it. name)
78
+ dependencyNode. appendNode(' version' , it. version)
84
79
}
85
80
}
86
81
}
87
82
}
88
83
}
89
- repositories {
90
- // The repository to publish to, Sonatype/MavenCentral
91
- maven {
92
- // This is an arbitrary name, you may also use "mavencentral" or
93
- // any other name that's descriptive for you
94
- // name = "XRouter-Android"
95
- url = uri(' ../repo' )
84
+ }
85
+
86
+ afterEvaluate {
87
+ publishing {
88
+ publications {
89
+ if (isAar) {
90
+ release(MavenPublication , configurePublication)
91
+ } else {
92
+ mavenJava(MavenPublication , configurePublication)
93
+ }
94
+ }
95
+ repositories {
96
+ maven {
97
+ url = uri(' ../repo' )
98
+ }
96
99
}
97
100
}
98
101
}
@@ -102,7 +105,8 @@ signing {
102
105
sign publishing. publications
103
106
}
104
107
105
- task zipRepo (type : Zip ) {
108
+ task zipRepo (type : Zip ) {
109
+ dependsOn isAar ? ' publishReleasePublicationToMavenRepository' : ' publishMavenJavaPublicationToMavenRepository'
106
110
def componentDirPath = " ${ PUBLISH_GROUP_ID.replace(".", "/")} /$PUBLISH_ARTIFACT_ID /$PUBLISH_VERSION "
107
111
108
112
archiveBaseName = PUBLISH_ARTIFACT_ID
@@ -114,9 +118,9 @@ task zipRepo(type: Zip) {
114
118
}
115
119
}
116
120
117
-
118
- task publishSonatype (dependsOn : [' publishReleasePublicationToMavenRepository' , ' zipRepo' ]) {
121
+ task publishSonatype {
119
122
group = " publishing"
123
+ dependsOn ' zipRepo'
120
124
doLast {
121
125
def publishZipFile = file(" ../publish/$PUBLISH_ARTIFACT_ID -$PUBLISH_VERSION " + " .zip" )
122
126
def uploadToken = Base64 . getEncoder(). encodeToString(" $ossrhUsername :$ossrhPassword " . getBytes(" UTF-8" ))
0 commit comments