-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle
120 lines (110 loc) · 4.39 KB
/
build.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
// uses https://github.com/Codearte/gradle-nexus-staging-plugin to create manage (create, drop, close, promote the OSSRH repository)
// uses https://github.com/marcphilipp/nexus-publish-plugin to explicitly create the staging repository before pulishing to nexus to ensure all the artifacts are in the same staging repository
// keep an eye on https://github.com/gradle-nexus/publish-plugin as it will replace these two plugins
plugins {
id "java"
id "signing"
id "maven-publish"
id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
}
group = "io.github.rwinch"
// configure all java components to be published
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
// ossrh requires javadoc and sources https://central.sonatype.org/pages/requirements.html
java {
withJavadocJar()
withSourcesJar()
}
// ossrh requries signing https://central.sonatype.org/pages/requirements.html
// https://docs.gradle.org/current/userguide/signing_plugin.html
// this only configures signing if the key is found
// For signing you need to make signingKey and signingPassword available properties See https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties
// The following makes the key available via the Gradle Property signingKey
// export ORG_GRADLE_PROJECT_signingKey=`cat test-private.pgp`
// export ORG_GRADLE_PROJECT_signingPassword="password"
// After making the Gradle properties above available, you can try signing using
// ./gradlew signMavenPublication
//
// NOTE: If you are using the legacy publishing you need to sign using the info at https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signing_pom_files
def hasSigningKey = project.hasProperty("signingKeyId") || project.hasProperty("signingKey")
if(hasSigningKey) {
sign(project)
}
void sign(Project project) {
project.signing {
required { project.gradle.taskGraph.hasTask("publish") }
def signingKeyId = project.findProperty("signingKeyId")
def signingKey = project.findProperty("signingKey")
def signingPassword = project.findProperty("signingPassword")
if (signingKeyId) {
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
} else if (signingKey) {
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign publishing.publications.maven
}
}
// customize the pom so it complies to Maven central requirements https://central.sonatype.org/pages/requirements.html
// https://docs.gradle.org/current/userguide/maven_plugin.html#sec:maven_pom_generation
project.plugins.withType(MavenPublishPlugin).all {
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
publishing.publications.withType(MavenPublication).all { mavenPublication ->
mavenPublication.pom {
name = "${project.group}:${project.name}"
description = name
url = "https://github.com/rwinch/gradle-publish-ossrh-sample"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0"
}
}
developers {
developer {
id = "rwinch"
name = "Rob Winch"
email = "rwinch@noreply.github.com"
}
}
scm {
connection = "scm:git:https://github.com/rwinch/gradle-publish-ossrh-sample"
developerConnection = "scm:git:ssh://github.com/rwinch/gradle-publish-ossrh-sample.git"
url = "https://github.com/rwinch/gradle-publish-ossrh-sample"
}
}
}
}
nexusPublishing {
repositories {
sonatype()
// OR, if you registered with Sonatype after 24 February 2021
// sonatype {
// nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
// snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
// }
}
// these are not strictly required. The default timeouts are set to 1 minute. But Sonatype can be really slow.
// If you get the error "java.net.SocketTimeoutException: timeout", these lines will help.
connectTimeout = Duration.ofMinutes(3)
clientTimeout = Duration.ofMinutes(3)
}
// configure publishing to a local directory for testing (not necessary)
// ./gradlew publishMavenToLocal
// tree ./build/repos/releases
publishing {
repositories {
maven {
name = "local"
// change URLs to point to your repos, e.g. http://my.org/repo
def releasesRepoUrl = "$buildDir/repos/releases"
def snapshotsRepoUrl = "$buildDir/repos/snapshots"
url = version.endsWith("SNAPSHOT") ? snapshotsRepoUrl : releasesRepoUrl
}
}
}