-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathjava-publish.gradle
210 lines (192 loc) · 6.28 KB
/
java-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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import java.nio.charset.StandardCharsets
def decode64(String varName) {
String envValue = System.env[varName]
if (envValue == null) {
return ""
} else {
return new String(envValue.decodeBase64(), "UTF-8")
}
}
if (project.parent == null) {
group = 'com.diffplug.spotless'
def pass = System.env['ORG_GRADLE_PROJECT_nexus_pass64']
if (pass != null) {
pass = pass.decodeBase64()
}
// it's the root project
apply plugin: 'io.github.gradle-nexus.publish-plugin'
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username = System.env['ORG_GRADLE_PROJECT_nexus_user']
password = decode64('ORG_GRADLE_PROJECT_nexus_pass64')
}
}
}
def initTask = tasks.named('initializeSonatypeStagingRepository')
allprojects {
initTask.configure {
shouldRunAfter(tasks.withType(Sign))
}
}
return
}
///////////
// MAVEN //
///////////
java {
withJavadocJar()
withSourcesJar()
}
tasks.named('sourcesJar') {
dependsOn 'jar'
}
apply plugin: 'maven-publish'
apply plugin: 'signing'
// Where it's possible to name parameters and methods clearly enough
// that javadoc is not necessary, why make the code bigger?
//
// Thus, no javadoc warnings.
javadoc {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('Xwerror', '-quiet')
}
// make sure bad javadoc breaks the build
tasks.named('check') {
dependsOn tasks.named('javadoc')
}
// use markdown in javadoc
def makeLink = { url, text -> "<a href=\"${url}\" style=\"text-transform: none;\">${text}</a>" }
def javadocInfo = '<h2>' + makeLink("https://github.com/${org}/${name}", "${group}:${project.ext.artifactId}:${version}") +
' by ' + makeLink('https://www.diffplug.com', 'DiffPlug') + '</h2>'
String dotdotGradle = project.name.startsWith('eclipse-') ? '../../gradle' : '../gradle'
javadoc {
options.encoding = 'UTF-8'
// Where it's possible to name parameters and methods clearly enough
// that javadoc is not necessary, why make the code bigger?
//
// Thus, no javadoc warnings.
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('source', '11')
// setup the header
options.header javadocInfo
// setup links
options.linksOffline('https://docs.gradle.org/6.1.1/javadoc/', "${dotdotGradle}/javadoc/gradle")
// links to javadoc from the other versions
options.linksOffline("https://javadoc.io/static/com.diffplug.spotless/spotless-lib/${rootProject.spotlessChangelog.versionLast}", "${dotdotGradle}/javadoc/spotless-lib")
options.linksOffline("https://javadoc.io/static/com.diffplug.spotless/spotless-lib-extra/${rootProject.spotlessChangelog.versionLast}", "${dotdotGradle}/javadoc/spotless-lib-extra")
}
////////////////
// PUBLISHING //
////////////////
final MAVEN_PLUGIN_ARTIFACT_NAME = 'spotless-maven-plugin'
boolean isExt = project.name.startsWith('eclipse-')
boolean isPluginMaven = project.ext.artifactId == 'spotless-maven-plugin'
model {
publishing {
publications {
pluginMaven(MavenPublication) {
if (project.ext.artifactId != 'spotless-plugin-gradle') {
from components.java
}
groupId project.group
artifactId project.ext.artifactId
version project.version
def projectExtArtifactId = project.ext.artifactId
def projectDescription = project.description
def projectOrg = project.org
def rootProjectName = rootProject.name
pom.withXml {
// add MavenCentral requirements to the POM
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
name projectExtArtifactId
description projectDescription
url "https://github.com/${projectOrg}/${rootProjectName}"
scm {
url "https://github.com/${projectOrg}/${rootProjectName}"
connection "scm:git:https://github.com/${projectOrg}/${rootProjectName}.git"
developerConnection "scm:git:ssh:git@github.com/${projectOrg}/${rootProjectName}.git"
}
licenses {
if (isExt) {
license {
name 'Eclipse Public License - v 1.0'
url 'https://www.eclipse.org/legal/epl-v10.html'
distribution 'repo'
}
} else {
license {
name 'The Apache Software License, Version 2.0'
url 'https://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
if (isPluginMaven) {
// Maven plugin required Maven 3.1.0+ to run
prerequisites { maven '3.1.0' }
}
developers {
if (isExt) {
project.ext.developers.each { extId, extValues ->
developer {
id extId
name extValues['name']
email extValues['email']
}
}
} else {
if (isPluginMaven) {
developer {
id 'lutovich'
name 'Konstantin Lutovich'
email 'konstantin.lutovich@neotechnology.com'
}
}
developer {
id 'nedtwigg'
name 'Ned Twigg'
email 'ned.twigg@diffplug.com'
}
}
}
}
}
}
}
}
}
if (System.env['JITPACK'] == 'true' || version.endsWith('-SNAPSHOT')) {
signing {
setRequired(false)
}
} else {
signing {
String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64')
useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase'])
sign(publishing.publications)
}
// find the project with the changelog (this project for plugins, root project for libs)
def changelogTasks = (tasks.names.contains('changelogBump') ? project : rootProject).tasks
// ensures that nothing will be built if changelogPush will end up failing
tasks.named('jar').configure {
dependsOn changelogTasks.named('changelogCheck')
}
// ensures that changelog bump and push only happens if the publish was successful
def thisProj = project
changelogTasks.named('changelogBump').configure {
dependsOn ":${thisProj.path}:publishPluginMavenPublicationToSonatypeRepository"
dependsOn ":closeAndReleaseSonatypeStagingRepository"
// if we have a Gradle plugin, we need to push it up to the plugin portal too
if (thisProj.tasks.names.contains('publishPlugins')) {
dependsOn thisProj.tasks.named('publishPlugins')
}
}
}
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}