|
| 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