-
Notifications
You must be signed in to change notification settings - Fork 9
/
maven_upload.gradle
143 lines (122 loc) · 4.12 KB
/
maven_upload.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
/*
* gradle script to upload archives to maven central and Sonatype OSS
*
* How to use:
* 1. copy the script file in the same directoy like your build.gradle
* 2. Embed the script in your build.gradle file underneath(!) your 'group' and 'version' definition with:
* apply from: "maven_upload.gradle"
*
* It's important that the group and version information is above the 'apply' line. Otherwise these values aren't
* available in this build script.
* 3. Add a gradle.properties file with informations about your project that are used in the generated pom.xml file.
*
* This script uses the following properties:
*
* project_name = <your project name>
* project_description= <a description of the project>
* project_url=<url to the project webpage>
* project_scm=<scm link, i.e. 'scm:[email protected]:username/project.git'>
* project_license_name= <name of the license>
* project_license_url= <url to the license text file>
* project_license_distribution=<how the license is distributed, typically 'repo'>
* project_developer_name=<the name of the developer>
*
* 4. Perform a snapshot release with:
* gradle uploadArchives -Psnapshot
*
* 5. Perform a regular release with:
* gradle uploadArchives -Prelease
*
*/
apply plugin: "maven"
apply plugin: "signing"
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = "javadoc"
from "build/docs/javadoc"
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = "sources"
}
artifacts {
archives jar
archives javadocJar
archives sourcesJar
}
def sonatypeRepositoryUrl
def isDevBuild
def isSnapshotBuild
def isReleaseBuild
if (hasProperty("release")) {
println "release"
isReleaseBuild = true
sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
} else if (hasProperty("snapshot")) {
println "snapshot"
isSnapshotBuild = true
version += "-SNAPSHOT"
sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
} else {
println "dev build"
isDevBuild = true
}
//********* artifact signing *********
if (isReleaseBuild) {
signing {
sign configurations.archives
}
} else {
task signArchives {
// do nothing
}
}
uploadArchives {
repositories {
if (isDevBuild) {
mavenLocal()
} else {
mavenDeployer {
if (isReleaseBuild) {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
}
repository(url: sonatypeRepositoryUrl) {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
pom.project {
name = project_name
packaging = "jar"
description project_description
url project_url
scm {
url project_scm
connection project_scm
developerConnection project_scm
}
licenses {
license {
name project_license_name
url project_license_url
distribution project_license_distribution
}
}
developers {
developer {
id project_developer_name
name project_developer_name
}
}
}
}
}
}
}
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.allTasks.any { it instanceof Sign }) {
// Use Java 6's console to read from the console (no good for a CI environment)
Console console = System.console()
console.printf "\n\nWe have to sign some things in this build.\n\nPlease enter your signing details.\n\n"
def password = console.readPassword("PGP Private Key Password: ")
allprojects { ext."signing.password" = password }
console.printf "\nThanks.\n\n"
}
}