Skip to content

Commit cf2d610

Browse files
committed
Fix publish problem
1 parent 9c5c4d6 commit cf2d610

File tree

3 files changed

+127
-16
lines changed

3 files changed

+127
-16
lines changed

gradle/publish.gradle

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
}

nestedtouch/build.gradle

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
4-
apply plugin: 'maven-publish'
54
group = 'com.github.YvesCheung'
65

76
android {
@@ -38,12 +37,12 @@ tasks.withType(JavaCompile) {
3837
options.encoding = "UTF-8"
3938
}
4039

41-
// 打包源码
42-
task sourcesJar(type: Jar) {
43-
from android.sourceSets.main.java.srcDirs
44-
classifier = 'sources'
40+
ext {
41+
libraryName = 'nestedtouch'
42+
libraryDescription = 'A solution for NestedScrolling'
43+
siteUrl = 'https://github.com/YvesCheung/TouchEventBus'
44+
gitUrl = 'https://github.com/YvesCheung/TouchEventBus.git'
45+
libraryVersion = version
4546
}
4647

47-
artifacts {
48-
archives sourcesJar
49-
}
48+
apply from: '../gradle/publish.gradle'

toucheventbus/build.gradle

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply plugin: 'com.android.library'
2-
apply plugin: 'maven-publish'
32
group = 'com.github.YvesCheung'
43

54
android {
@@ -34,12 +33,12 @@ tasks.withType(JavaCompile) {
3433
options.encoding = "UTF-8"
3534
}
3635

37-
// 打包源码
38-
task sourcesJar(type: Jar) {
39-
from android.sourceSets.main.java.srcDirs
40-
classifier = 'sources'
36+
ext {
37+
libraryName = 'toucheventbus'
38+
libraryDescription = 'A solution for Non-Nested Scrolling'
39+
siteUrl = 'https://github.com/YvesCheung/TouchEventBus'
40+
gitUrl = 'https://github.com/YvesCheung/TouchEventBus.git'
41+
libraryVersion = version
4142
}
4243

43-
artifacts {
44-
archives sourcesJar
45-
}
44+
apply from: '../gradle/publish.gradle'

0 commit comments

Comments
 (0)