From cdff9551180f46655ddbbf79d02ec751bd9ebdae Mon Sep 17 00:00:00 2001 From: Pedro Loureiro Date: Wed, 1 Jul 2020 17:24:48 +0100 Subject: [PATCH] Add maven publishing and upload to Bintray (#2) --- bintray.build.gradle | 66 ++++++++++++++++++++++++++++++++++++++++ build.gradle | 7 +++-- mvflow-core/build.gradle | 3 ++ publishing.build.gradle | 39 ++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 bintray.build.gradle create mode 100644 publishing.build.gradle diff --git a/bintray.build.gradle b/bintray.build.gradle new file mode 100644 index 0000000..8c6ce8f --- /dev/null +++ b/bintray.build.gradle @@ -0,0 +1,66 @@ +apply plugin: "com.jfrog.bintray" + +afterEvaluate { + // needs afterEvaluate to load project description from module's build.gradle + loadLocalBintrayProperties() + + bintray { + // https://github.com/bintray/gradle-bintray-plugin + user = readProperty('BINTRAY_USER') + key = readProperty('BINTRAY_KEY') + publications = ["MVFlowPublication"] + pkg { + repo = 'MVFlow' + name = project.name + assert project.description: "Missing description for project :${project.name} to be used for uploading to Bintray" + desc = project.description + licenses = ['MIT'] + websiteUrl = 'https://github.com/pedroql/mvflow' + issueTrackerUrl = 'https://github.com/pedroql/mvflow/issues' + vcsUrl = 'https://github.com/pedroql/mvflow.git' + // the next line requires extra authentication + // githubRepo = 'pedroql/mvflow' + version { + name = project.version + released = new Date() + vcsTag = readVcsTag() + } +// publish = true //[Default: false] + dryRun = true //[Default: false] +// override = true //[Default: false] Whether to override version artifacts already published + } + } + +} + +static private def readProperty(propertyName) { + def value = System.getProperty(propertyName) ?: System.getenv(propertyName) + if (value == null) { + throw new NullPointerException("Missing property $propertyName") + } + return value +} + +private static def readVcsTag() { + return System.getProperty("VCS_TAG") +} + +private def loadLocalBintrayProperties() { + Properties properties = new Properties() + def propertiesFile = project.rootProject.file('local.properties') + if (propertiesFile.exists()) { + properties.load(propertiesFile.newDataInputStream()) + + println("Loading Bintray properties into system") + loadPropertyIntoSystem("BINTRAY_USER", properties) + loadPropertyIntoSystem("BINTRAY_KEY", properties) + } +} + +private static void loadPropertyIntoSystem(String propertyName, Map properties) { + def missingInSystem = !System.properties.containsKey(propertyName) + def presentInLocalProperties = propertyName in properties + if (missingInSystem && presentInLocalProperties) { + System.setProperty(propertyName, properties[propertyName].toString()) + } +} diff --git a/build.gradle b/build.gradle index 9d209b6..50c2324 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version '1.3.72' apply false + id "org.jetbrains.kotlin.jvm" version "1.3.72" apply false + id "com.jfrog.bintray" version "1.8.5" apply false } allprojects { @@ -8,7 +9,9 @@ allprojects { } subprojects { - apply plugin: 'org.jetbrains.kotlin.jvm' + apply plugin: "org.jetbrains.kotlin.jvm" + apply from: "$rootDir/publishing.build.gradle" + apply from: "$rootDir/bintray.build.gradle" repositories { mavenCentral() diff --git a/mvflow-core/build.gradle b/mvflow-core/build.gradle index ac67bdf..1b22010 100644 --- a/mvflow-core/build.gradle +++ b/mvflow-core/build.gradle @@ -15,3 +15,6 @@ tasks.test { events("passed", "skipped", "failed") } } + +// project description is sent to Bintray during bintrayUpload task +project.description = "Core functionality of MVFlow" diff --git a/publishing.build.gradle b/publishing.build.gradle new file mode 100644 index 0000000..70ba6c8 --- /dev/null +++ b/publishing.build.gradle @@ -0,0 +1,39 @@ +apply plugin: "maven-publish" + +task sourceJar(type: Jar) { + from sourceSets.main.allSource + classifier "sources" +} + +publishing { + // https://docs.gradle.org/5.0/dsl/org.gradle.api.publish.maven.MavenPublication.html + publications { + MVFlowPublication(MavenPublication) { + from components.java + artifact sourceJar + pom { + description = "Simple MVI architecture using Kotlin Flows" + url = "https://github.com/pedroql/mfflow" + licenses { + license { + name = 'The MIT License' + url = 'https://opensource.org/licenses/MIT' + distribution = 'repo' + } + } + scm { + connection = "scm:git:https://github.com/pedroql/mvflow.git" + developerConnection = "scm:git:git@github.com/pedroql/mvflow.git" + url = "https://github.com/pedroql/mfflow" + } + } + } + + } + repositories { + maven { + url = uri("$buildDir/local-maven-repository") + name = "local" + } + } +}