Skip to content

Commit 2ba2514

Browse files
committed
Produce more complete POMs with the Grails publishing plugin
1 parent 524d71b commit 2ba2514

File tree

2 files changed

+133
-4
lines changed

2 files changed

+133
-4
lines changed

grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsCentralPublishGradlePlugin.groovy

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ grailsPublish {
4545
license = 'APACHE 2.0'
4646
issueTrackerUrl = 'http://github.com/myname/myplugin/issues'
4747
vcsUrl = 'http://github.com/myname/myplugin'
48+
title = "My plugin title"
4849
desc = "My plugin description"
50+
developers = [johndoe:"John Doe"]
4951
}
5052
5153
or
@@ -55,6 +57,9 @@ grailsPublish {
5557
key = 'key'
5658
githubSlug = 'foo/bar'
5759
license = 'APACHE 2.0'
60+
title = "My plugin title"
61+
desc = "My plugin description"
62+
developers = [johndoe:"John Doe"]
5863
}
5964
6065
The values can also be placed in PROJECT_HOME/gradle.properties or USER_HOME/gradle.properties
@@ -153,8 +158,8 @@ The values can also be placed in PROJECT_HOME/gradle.properties or USER_HOME/gra
153158
throw new RuntimeException(getErrorMessage("issueTrackerUrl"))
154159
}
155160

156-
if(publishExtension.license) {
157-
bintrayExtension.pkg.licenses = [publishExtension.license] as String[]
161+
if(publishExtension.license?.name) {
162+
bintrayExtension.pkg.licenses = [publishExtension.license.name] as String[]
158163
}
159164
else if(!bintrayExtension.pkg.licenses) {
160165
throw new RuntimeException(getErrorMessage("license"))
@@ -185,11 +190,89 @@ The values can also be placed in PROJECT_HOME/gradle.properties or USER_HOME/gra
185190
publications {
186191
maven(MavenPublication) {
187192
pom.withXml {
188-
def pomNode = asNode()
193+
Node pomNode = asNode()
194+
def extension = project.extensions.findByType(GrailsPublishExtension)
189195
if(pomNode.dependencyManagement) {
190196
pomNode.dependencyManagement[0].replaceNode {}
191197
}
192198

199+
if(extension != null) {
200+
pomNode.children().last() + {
201+
def title = extension.title ?: project.name
202+
delegate.name title
203+
delegate.description extension.desc ?: title
204+
205+
def websiteUrl = extension.websiteUrl ?: extension.githubSlug ? "https://github.com/$extension.githubSlug" : ''
206+
if(!websiteUrl) {
207+
throw new RuntimeException(getErrorMessage('websiteUrl'))
208+
}
209+
210+
delegate.url websiteUrl
211+
212+
if(extension.license?.name == 'Apache-2.0') {
213+
214+
delegate.licenses {
215+
delegate.license {
216+
delegate.name 'The Apache Software License, Version 2.0'
217+
delegate.url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
218+
delegate.distribution extension.license.distribution
219+
}
220+
}
221+
}
222+
223+
if(extension.githubSlug) {
224+
delegate.scm {
225+
delegate.url "https://github.com/$extension.githubSlug"
226+
delegate.connection "scm:[email protected]:${extension.githubSlug}.git"
227+
delegate.developerConnection "scm:[email protected]:${extension.githubSlug}.git"
228+
}
229+
delegate.issueManagement {
230+
delegate.system "Github Issues"
231+
delegate.url "https://github.com/$extension.githubSlug/issues"
232+
}
233+
}
234+
else {
235+
if(extension.vcsUrl) {
236+
delegate.scm {
237+
delegate.url extension.vcsUrl
238+
delegate.connection "scm:$extension.vcsUrl"
239+
delegate.developerConnection "scm:$extension.vcsUrl"
240+
}
241+
}
242+
else {
243+
throw new RuntimeException(getErrorMessage('vcsUrl'))
244+
}
245+
246+
if(extension.issueTrackerUrl) {
247+
delegate.issueManagement {
248+
delegate.system "Issue Tracker"
249+
delegate.url extension.issueTrackerUrl
250+
}
251+
}
252+
else {
253+
throw new RuntimeException(getErrorMessage('issueTrackerUrl'))
254+
}
255+
256+
}
257+
258+
if(extension.developers) {
259+
260+
delegate.developers {
261+
for(entry in extension.developers.entrySet()) {
262+
delegate.developer {
263+
delegate.id entry.key
264+
delegate.name entry.value
265+
}
266+
}
267+
}
268+
}
269+
else {
270+
throw new RuntimeException(getErrorMessage('developers'))
271+
}
272+
}
273+
274+
}
275+
193276
// simply remove dependencies without a version
194277
// version-less dependencies are handled with dependencyManagement
195278
// see https://github.com/spring-gradle-plugins/dependency-management-plugin/issues/8 for more complete solutions

grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishExtension.groovy

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ class GrailsPublishExtension {
3535
* The the publishing key
3636
*/
3737
String key
38+
39+
/**
40+
* The username for the plugin portal
41+
*/
42+
String portalUser
43+
44+
/**
45+
* The password for the plugin portal
46+
*/
47+
String portalPassword
3848
/**
3949
* The website URL of the plugin
4050
*/
@@ -46,7 +56,17 @@ class GrailsPublishExtension {
4656
/**
4757
* The license of the plugin
4858
*/
49-
String license
59+
License license = new License()
60+
61+
/**
62+
* The developers of the plugin
63+
*/
64+
Map<String, String> developers = [:]
65+
66+
/**
67+
* Title of the plugin, defaults to the project name
68+
*/
69+
String title
5070

5171
/**
5272
* Description of the plugin
@@ -88,4 +108,30 @@ class GrailsPublishExtension {
88108
* Password for maven central
89109
*/
90110
String sonatypeOssPassword
111+
112+
License getLicense() {
113+
return license
114+
}
115+
116+
String getPortalUser() {
117+
return portalUser ?: user
118+
}
119+
120+
void setPortalUser(String portalUser) {
121+
this.portalUser = portalUser
122+
}
123+
124+
void setLicense(License license) {
125+
this.license = license
126+
}
127+
128+
void setLicense(String license) {
129+
this.license.name = license
130+
}
131+
132+
static class License {
133+
String name
134+
String url
135+
String distribution = 'repo'
136+
}
91137
}

0 commit comments

Comments
 (0)