From 3f351feab9acde129500a4b1316306102f0c2df8 Mon Sep 17 00:00:00 2001 From: mgabriel Date: Mon, 20 Aug 2018 11:18:04 +0200 Subject: [PATCH] prepare for jar publication --- .travis.yml | 7 ++ build.gradle | 55 +++++++++++++++- gradle/wrapper/gradle-wrapper.properties | 3 +- scripts/bintray-deploy.gradle | 83 ++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 scripts/bintray-deploy.gradle diff --git a/.travis.yml b/.travis.yml index 5dcb346..84de67e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,5 +8,12 @@ script: - ./gradlew check - ./gradlew javadoc - ./gradlew jacocoTestReport +deploy: + provider: script + skip_cleanup: true + script: ./gradlew bintrayUpload -Ddeployment=true + on: + tags: true + jdk: oraclejdk8 after_success: - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/build.gradle b/build.gradle index 438448c..64dbeea 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,38 @@ buildscript { + project.ext.DEPLOYMENT = System.getProperty('deployment') ?: false + project.ext.VCS_TAG = System.getProperty('TRAVIS_TAG') ?: System.getenv('TRAVIS_TAG') + project.ext.POM = [ + groupId : 'ch.streamly', + artifactId : 'chronicle-flux', + description: 'A reactive driver for Chronicle-Queue.', + developers : [ + [ + id : 'mgabriel', + name : 'Mathieu Gabriel', + email: 'dev@streamly.ch' + ] + ]] + project.ext.INFO = [ + repo : 'https://github.com/matgabriel/chronicle-flux.git', + url : 'https://github.com/matgabriel/chronicle-flux', + github : 'https://github.com/matgabriel/chronicle-flux', + githubIssues: 'https://github.com/matgabriel/chronicle-flux/issues' + ] + project.ext.BINTRAY = [ + repo : 'streamly-repo', + name : 'ch.streamly:chronicle-flux', + organization: 'streamly', + userName : System.getenv('BINTRAY_USER'), + apiToken : System.getenv('BINTRAY_API_TOKEN') + ] + repositories { mavenCentral() jcenter() } } -group 'ch.streamly' +group POM.groupId apply plugin: 'java' @@ -13,7 +40,7 @@ apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'jacoco' -sourceCompatibility = 1.8 +sourceCompatibility = JavaVersion.VERSION_1_8 def chronicleVersion = '5.16.8' def reactorVersion = '3.1.7.RELEASE' @@ -22,6 +49,15 @@ repositories { mavenCentral() } +if (DEPLOYMENT) { + apply plugin: 'maven' + apply plugin: 'maven-publish' + apply plugin: 'com.jfrog.bintray' + + println 'Applying deployment scripts' + apply from: './scripts/bintray-deploy.gradle' +} + dependencies { compile "org.slf4j:slf4j-api:1.7.25" compile "io.projectreactor:reactor-core:$reactorVersion" @@ -48,6 +84,21 @@ jacocoTestReport { } } +task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource +} + +javadoc.failOnError = false +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} + +artifacts { + archives sourcesJar + archives javadocJar +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d2c45a4..d36554b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Mon Aug 20 10:35:14 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip diff --git a/scripts/bintray-deploy.gradle b/scripts/bintray-deploy.gradle new file mode 100644 index 0000000..ae1dfd5 --- /dev/null +++ b/scripts/bintray-deploy.gradle @@ -0,0 +1,83 @@ +project.ext.getDeploymentVersion = { + String tmpDeploymentVersion = VCS_TAG.replaceFirst("v", ""); + if (!tmpDeploymentVersion.matches("\\d+\\.\\d+\\.\\d+")) { + throw new RuntimeException("Version is not valid. Correct format is like 1.0.2 but was " + tmpDeploymentVersion) + } + return tmpDeploymentVersion; +} + +bintrayUpload.doFirst { + println "Deploying version ${getDeploymentVersion()} from vscTag ${VCS_TAG}" +} + +def pomConfig = { + licenses { + license { + name "The Apache Software License, Version 2.0" + url "http://www.apache.org/licenses/LICENSE-2.0.txt" + distribution "repo" + } + } + developers { + POM.developers.each { dev -> + developer { + id dev.id + name dev.name + email dev.email + } + } + } + + scm { + connection "scm:git:${INFO.repo}" + developerConnection "scm:git:${INFO.repo}" + url "${INFO.repo}" + } +} + +publishing { + publications { + mavenPublication(MavenPublication) { + from components.java + artifact sourcesJar { + classifier "sources" + } + artifact javadocJar { + classifier "javadoc" + } + groupId POM.groupId + artifactId POM.artifactId + version getDeploymentVersion() + pom.withXml { + def root = asNode() + root.appendNode('description', POM.description) + root.appendNode('name', POM.artifactId) + root.appendNode('url', INFO.url) + root.children().last() + pomConfig + } + } + } +} + +bintray { + user = BINTRAY.userName + key = BINTRAY.apiToken + publications = ['mavenPublication'] + dryRun = !DEPLOYMENT // Whether to run this as dry-run, without deploying + publish = DEPLOYMENT // Whether version should be auto published after an upload + override = false // Whether to override version artifacts already published + + pkg { + repo = BINTRAY.repo + name = BINTRAY.name + userOrg = BINTRAY.organization + licenses = ['Apache-2.0'] + vcsUrl = INFO.repo + version { + name = getDeploymentVersion() + desc = getDeploymentVersion() + released = new Date() + } + } + +}