Skip to content

Commit e812275

Browse files
author
Martin
committed
added com.jfrog.bintray plugin for publishing
1 parent 9b9d866 commit e812275

File tree

2 files changed

+133
-18
lines changed

2 files changed

+133
-18
lines changed

build.gradle

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,32 @@ plugins {
1919
* Android>Lint>Correctness>Obsolete Gradle Dependency
2020
*/
2121
id 'com.github.ben-manes.versions' version '0.14.0'
22+
// for publishing
23+
id "com.jfrog.bintray" version "1.7.3"
2224
}
2325

26+
// https://docs.travis-ci.com/user/environment-variables/
27+
def isCi = System.getenv("TRAVIS") != null
28+
2429
group 'com.tmtron.enums'
2530
version '1.0-SNAPSHOT'
31+
description 'Annotation processor that builds an enum mapper which causes a compile-time error when you forget an enum'
32+
ext {
33+
bintrayDryRun = true
34+
}
2635

2736
subprojects {
2837
apply plugin: 'java'
2938

39+
if (!isCi) {
40+
// we don't need the bintray features for the ci build
41+
apply from: rootProject.file('gradle/bintray.gradle')
42+
}
43+
44+
/*
45+
when I activate the licesne pluign, the bintray plugin creates an invalid pom file!
46+
http://stackoverflow.com/questions/43820811/using-the-bintray-plugin-and-license-gradle-plugin-together
47+
3048
apply plugin: "com.github.hierynomus.license"
3149
license {
3250
header rootProject.file('LICENSE_HEADER')
@@ -36,24 +54,7 @@ subprojects {
3654
}
3755
ext.year = Calendar.getInstance().get(Calendar.YEAR)
3856
}
39-
40-
/* create a jar for sources and java-docs
41-
* http://stackoverflow.com/a/11475089/6287240
42-
*/
43-
task sourcesJar(type: Jar, dependsOn: classes) {
44-
classifier = 'sources'
45-
from sourceSets.main.allSource
46-
}
47-
48-
task javadocJar(type: Jar, dependsOn: javadoc) {
49-
classifier = 'javadoc'
50-
from javadoc.destinationDir
51-
}
52-
53-
artifacts {
54-
archives sourcesJar
55-
archives javadocJar
56-
}
57+
*/
5758
}
5859

5960
repositories {

gradle/bintray.gradle

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
apply plugin: 'maven'
2+
apply plugin: 'maven-publish'
3+
apply plugin: 'com.jfrog.bintray'
4+
5+
def vcProvider = 'github'
6+
def vcProviderUser = 'tmtron'
7+
def vcProviderProject = 'enum-mapper'
8+
// e.g. https://github.com/tmtron/enum-mapper
9+
def vcProviderUrl = "https://${vcProvider}.com/${vcProviderUser}/${vcProviderProject}"
10+
def vcProviderScmUrl = "scm:git:${vcProviderUrl}.git"
11+
def bintrayPackage = "com.tmtron.${vcProviderProject}"
12+
13+
bintray {
14+
// defined in ~/.gradle/gradle.properties
15+
user = "$bintray_user"
16+
key = "$bintray_api_key"
17+
publications = ['PublicationTmtron']
18+
pkg {
19+
repo = 'maven'
20+
name = bintrayPackage
21+
licenses = ['Apache-2.0']
22+
vcsUrl = vcProviderScmUrl
23+
version {
24+
name = "$project.version"
25+
gpg {
26+
sign = true
27+
}
28+
}
29+
}
30+
// whether to run this as dry-run, without deploying
31+
dryRun = bintrayDryRun
32+
}
33+
34+
if (!bintrayDryRun) {
35+
if ("$project.version".endsWith('-SNAPSHOT')) {
36+
throw new GradleException("BinTray: uploading s snapshot version " +
37+
">$project.version< is not allowed!" +
38+
"\nChange the version number or set ext.bintrayDryRun=true")
39+
}
40+
}
41+
42+
bintrayUpload.doLast {
43+
if (bintrayDryRun) {
44+
System.err.println "BinTray: DryRun is true!"
45+
}
46+
}
47+
48+
/* create a jar for sources and java-docs
49+
* http://stackoverflow.com/a/11475089/6287240
50+
*/
51+
task sourcesJar(type: Jar, dependsOn: classes) {
52+
from sourceSets.main.allSource
53+
classifier = 'sources'
54+
}
55+
56+
task javadocJar(type: Jar, dependsOn: javadoc) {
57+
from javadoc.destinationDir
58+
classifier = 'javadoc'
59+
}
60+
61+
jar.dependsOn sourcesJar
62+
jar.dependsOn javadocJar
63+
64+
artifacts {
65+
archives sourcesJar
66+
archives javadocJar
67+
}
68+
69+
// Create the pom configuration:
70+
def pomConfig = {
71+
licenses {
72+
license {
73+
name "The Apache Software License, Version 2.0"
74+
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
75+
distribution "repo"
76+
}
77+
}
78+
developers {
79+
developer {
80+
id "martin"
81+
name "Martin"
82+
email "martin@tmtron.com"
83+
}
84+
}
85+
scm {
86+
connection vcProviderScmUrl
87+
developerConnection vcProviderScmUrl
88+
url "${vcProviderUrl}/tree/master"
89+
}
90+
}
91+
92+
// Create the publication with the pom configuration:
93+
publishing {
94+
publications {
95+
PublicationTmtron(MavenPublication) {
96+
from components.java
97+
98+
artifact sourcesJar
99+
artifact javadocJar
100+
101+
groupId "$project.group"
102+
artifactId "$project.name"
103+
version "$project.version"
104+
105+
pom.withXml {
106+
def root = asNode()
107+
root.appendNode('description', project.description)
108+
root.appendNode('name', "${project.group}:${project.name}")
109+
root.appendNode('url', vcProviderUrl)
110+
root.children().last() + pomConfig
111+
}
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)