Skip to content

Commit 75b78c8

Browse files
committed
add maven central publish config
1 parent 67eadbc commit 75b78c8

File tree

1 file changed

+106
-1
lines changed

1 file changed

+106
-1
lines changed

build.gradle

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
plugins {
22
id 'java'
3+
id "java-library"
4+
id "maven-publish"
5+
id "signing"
6+
id "com.github.johnrengelman.shadow" version "6.1.0"
37
}
48

59
group 'cn.alapi'
@@ -21,4 +25,105 @@ test {
2125
filter {
2226
includeTestsMatching "*Test"
2327
}
24-
}
28+
}
29+
30+
task sourceJar(type: Jar) {
31+
classifier "sources"
32+
from sourceSets.main.allJava
33+
}
34+
35+
task javadocJar(type: Jar, dependsOn: javadoc) {
36+
classifier "javadoc"
37+
from javadoc.destinationDir
38+
}
39+
40+
javadoc {
41+
description = "生成jar格式的javadoc。"
42+
// 只显示 protected 和 public 的类和成员
43+
options.memberLevel = JavadocMemberLevel.PROTECTED
44+
options.author = true
45+
options.version = true
46+
options.header = project.name
47+
// 静默javadoc检查(比如不支持@date会报错等),jdk 8+
48+
options.addStringOption('Xdoclint:none', '-quiet')
49+
// 防止本地打开中文乱码
50+
options.addStringOption("charset", "UTF-8")
51+
// suppress warnings due to cross-module @see and @link references;
52+
// note that global 'api' task does display all warnings.
53+
logging.captureStandardError LogLevel.INFO
54+
// suppress "## warnings" message
55+
logging.captureStandardOutput LogLevel.INFO
56+
// 编码一定要配置否则直接出错
57+
options.encoding = "UTF-8"
58+
options.charSet = "UTF-8"
59+
}
60+
61+
publishing {
62+
publications {
63+
mavenJava(MavenPublication) {
64+
groupId = 'cn.alapi'
65+
artifactId = 'javasdk'
66+
version = '1.0'
67+
from components.java
68+
69+
artifact sourceJar
70+
artifact javadocJar
71+
72+
pom {
73+
name = 'alapi-javasdk'
74+
description = 'Java SDK for ALAPI.'
75+
url = 'https://github.com/ALAPI-SDK/JAVA-SDK'
76+
licenses {
77+
license {
78+
name = 'The MIT License'
79+
url = 'https://opensource.org/licenses/MIT'
80+
distribution = 'repo'
81+
comments = 'A business-friendly OSS license'
82+
}
83+
}
84+
developers {
85+
developer {
86+
name = 'yeliulee'
87+
email = 'yeliuleet@gmail.com'
88+
roles = ['Java Developer']
89+
url = "https://www.yeliulee.com"
90+
}
91+
}
92+
scm {
93+
url = 'https://github.com/ALAPI-SDK/JAVA-SDK'
94+
connection = 'scm:git:https://github.com/ALAPI-SDK/JAVA-SDK.git'
95+
developerConnection = 'scm:git:git@github.com:ALAPI-SDK/JAVA-SDK.git'
96+
}
97+
}
98+
}
99+
}
100+
101+
repositories {
102+
maven {
103+
name "oss"
104+
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
105+
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
106+
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
107+
credentials {
108+
username = sonatypeUsername
109+
password = sonatypePassword
110+
}
111+
}
112+
}
113+
}
114+
115+
signing {
116+
sign publishing.publications.mavenJava
117+
}
118+
119+
jar.enabled = false
120+
shadowJar {
121+
baseName = 'alapi-javasdk'
122+
classifier = null
123+
version = '1.0.0'
124+
manifest {
125+
attributes 'Main-Class': 'cn.alapi.javasdk.AlapiClient'
126+
}
127+
}
128+
129+
assemble.dependsOn(shadowJar)

0 commit comments

Comments
 (0)