-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublish.gradle
108 lines (97 loc) · 3.36 KB
/
publish.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
apply plugin: 'maven'
apply plugin: 'signing'
version = VERSION
String group = GROUP_ID
String pomName = ARTIFACT_ID
String pomRepositoryUrl = PROJECT_URL
String pomScmUrl = SCM_URL
String pomDescription = PROJECT_DESCRIPTION
String pomLicenseName = LICENSE_NAME
String pomLicenseUrl = LICENSE_URL
String pomDeveloperId = DEVELOPER_ID
String pomDeveloperEmail = DEVELOPER_EMAIL
String pomDeveloperName = DEVELOPER_NAME
String organizationName = ORGANIZATION_NAME
String organizationUrl = ORGANIZATION_URL
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives jar, javadocJar, sourcesJar
}
def getOptional(String name) {
def env = System.getenv(name)
if(env != null){
System.out.println("Using property [${name}] from environment variables")
return java.util.Optional.of(env)
} else if(hasProperty(name)) {
System.out.println("Using property [${name}] from gradle properties")
return java.util.Optional.of(getProperty(name))
}
System.out.println("Missing property [${name}]")
return java.util.Optional.empty()
}
signing {
required {
def release = !project.version.contains("SNAPSHOT")
def uploading = project.gradle.taskGraph.hasTask("uploadArchives")
System.out.println("Signing Status [release=" + release + ", publishing=" + uploading + "]")
release && uploading
}
String key = getOptional("GPG_SIGNING_KEY").orElse("Unknown")
String password = getOptional("GPG_SIGNING_PASSWORD").orElse("Unknown")
useInMemoryPgpKeys(key, password)
sign configurations.archives
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
def username = getOptional('OSSRH_USERNAME').orElse('')
def password = getOptional('OSSRH_PASSWORD').orElse('')
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: username, password: password)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: username, password: password)
}
pom.project {
name pomName
description pomDescription
url pomRepositoryUrl
version version
groupId group
artifactId pomName
packaging 'jar'
scm {
connection pomScmUrl
developerConnection pomScmUrl
url pomScmUrl
}
licenses {
license {
name pomLicenseName
url pomLicenseUrl
distribution 'repo'
}
}
developers {
developer {
id pomDeveloperId
name pomDeveloperName
email pomDeveloperEmail
}
}
organization {
name = organizationName
url = organizationUrl
}
}
}
}
}