Skip to content

Commit

Permalink
feat(gradle): multi-module release, split logic into ext/libraries/re…
Browse files Browse the repository at this point in the history
…lease/standalone
  • Loading branch information
PLNech committed Nov 22, 2018
1 parent 4f631c2 commit a858eec
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 88 deletions.
72 changes: 4 additions & 68 deletions build.gradle
Expand Up @@ -2,6 +2,7 @@

buildscript {
apply from: 'libraries.gradle'
apply from: "ext.gradle"
repositories {
google()
jcenter()
Expand All @@ -10,25 +11,11 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.4.0-alpha02'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
}
ext.with {
VERSION = '1.13.0'
GROUP = 'com.algolia'
BASENAME = 'instantsearch-android'
CODENAME = GROUP + ":" + BASENAME
NAME = 'InstantSearch Android'
DESC = "A library to build instant-search applications on Android."
GITHUB = "algolia/instantsearch-android"
WEBSITE = "https://github.com/" + GITHUB
REPO = WEBSITE + ".git"
LICENSE = 'MIT'
LICENSE_URL = "http://www.opensource.org/licenses/mit-license.php"
VERSION_DESC = 'Version ' + VERSION
}
}

plugins {
id "com.github.ben-manes.versions" version "0.20.0" // exposes dependencyUpdates task
id 'com.github.dcendents.android-maven' version "2.1" // adds support for deploying to Mvn repos.
id 'com.github.dcendents.android-maven' version "2.1" // allows deploying to Mvn repos.
}

allprojects {
Expand All @@ -40,56 +27,5 @@ allprojects {
}

subprojects {
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.bintray"

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName VERSION
consumerProguardFiles "proguard-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

testOptions {
unitTests {
// Disable automatic throwing on system method calls.
// Rationale: We don't want to mock system methods (for example JSONArray.length),
// but rather ensure we use them correctly.
returnDefaultValues = true

// Required by Robolectric http://robolectric.org/getting-started/
includeAndroidResources = true

all {
testLogging {
events "skipped", "failed", "standardOut", "standardError"
exceptionFormat "full"
outputs.upToDateWhen { false }
}
}
}
}
}

dependencies {
testImplementation libraries.junit
testImplementation libraries.robolectric
testImplementation libraries.mockito
}

apply from: '../release.gradle'
}
apply from: "../common.gradle"
}
52 changes: 52 additions & 0 deletions common.gradle
@@ -0,0 +1,52 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.bintray"

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName VERSION
consumerProguardFiles "proguard-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

testOptions {
unitTests {
// Disable automatic throwing on system method calls.
// Rationale: We don't want to mock system methods (for example JSONArray.length),
// but rather ensure we use them correctly.
returnDefaultValues = true

// Required by Robolectric http://robolectric.org/getting-started/
includeAndroidResources = true

all {
testLogging {
events "skipped", "failed", "standardOut", "standardError"
exceptionFormat "full"
outputs.upToDateWhen { false }
}
}
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

testImplementation libraries.junit
testImplementation libraries.robolectric
testImplementation libraries.mockito
}
5 changes: 4 additions & 1 deletion core/build.gradle
@@ -1,9 +1,10 @@
//apply from: "../standalone.gradle" // Uncomment to use module in another project

ext {
BASENAME = 'instantsearch-android-core'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api libraries.eventbus
api libraries.algolia

Expand All @@ -13,3 +14,5 @@ dependencies {
exclude module: 'asm'
}
}

apply from: '../release.gradle'
2 changes: 1 addition & 1 deletion docgen/src/troubleshooting.md
Expand Up @@ -8,7 +8,7 @@ navWeight: 0
---


There are a few errors that you may encounter if your setup is not correct.
There are a few errors that you may encounter if your setup is not correct.
Here are the frequent errors and the appropriate solutions:

## No resource type specified
Expand Down
21 changes: 21 additions & 0 deletions ext.gradle
@@ -0,0 +1,21 @@
/**
* Extra properties applied by default to all modules.
*/
ext {
VERSION = '0.0.1-alpha10'
GROUP = 'com.algolia'
NAME = 'InstantSearch Android'
DESC = "A library to build instant-search applications on Android."
GITHUB = "algolia/instantsearch-android"
WEBSITE = "https://github.com/" + GITHUB
REPO = WEBSITE + ".git"
LICENSE = 'MIT'
LICENSE_URL = "http://www.opensource.org/licenses/mit-license.php"
VERSION_DESC = 'Version ' + VERSION

LABELS = ["android", "android-library",
"algolia", "search", "instant-search", "search-interface",
"faceted-search", "search-synonyms", "geo-search", "search-engine",
"widgets", "custom-widgets", "interface-builder",
"open-source"]
}
File renamed without changes.
2 changes: 1 addition & 1 deletion libraries.gradle
@@ -1,4 +1,4 @@
/*
/**
* Libraries that can be used by any submodule.
* */
ext {
Expand Down
37 changes: 27 additions & 10 deletions release.gradle
@@ -1,11 +1,16 @@
/*
* Tasks related to releasing InstantSearch.
* */
/**
* Tasks related to releasing InstantSearch modules.
* <b>Don't forget to adapt Extra properties for each module before applying this script!</b>
*/
ext {
CODENAME = GROUP + ":" + BASENAME
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) // dependencies
failOnError false // Errors about classes `R` and `BuildConfig` should not trigger failure
options.optionFiles << file('javadoc.options')
options.optionFiles << file('../javadoc.options')
options.links("http://docs.oracle.com/javase/8/docs/api")
options.linksOffline("http://d.android.com/reference", "$System.env.ANDROID_HOME/docs/reference")
options.encoding('UTF-8')
Expand Down Expand Up @@ -40,7 +45,6 @@ task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
}


// add sources jar tasks as artifacts
artifacts {
archives sourcesJar
Expand Down Expand Up @@ -94,16 +98,21 @@ publishing.publications {
root.appendNode("description", DESC) //TODO Find why description is missing from pom.xml

final dependenciesNode = asNode().appendNode('dependencies')
println "Adding dependencies node"

ext.addDependency = { Dependency dep, String scope ->
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified") {
return // ignore invalid dependencies
}
println "Adding dependency $dep.name ($scope) to pom.xml"

// Add InstantSearch prefix to our modules when releasing
//TODO: Find a way to avoid listing modules manually
final moduleNames = ["core", "ui"]
final depFinalName = dep.group == "com.algolia" && moduleNames.contains(dep.name) ?
"instantsearch-android-$dep.name" : dep.name
println "Adding dependency $depFinalName ($scope) to pom.xml"

final dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('artifactId', depFinalName)
dependencyNode.appendNode('version', dep.version)
dependencyNode.appendNode('scope', scope)

Expand Down Expand Up @@ -132,6 +141,9 @@ publishing.publications {
}
}

group = GROUP
version = VERSION

bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
Expand All @@ -140,8 +152,13 @@ bintray {
pkg {
repo = 'maven'
name = CODENAME
licenses = [LICENSE]
desc = DESC
websiteUrl = WEBSITE
issueTrackerUrl = WEBSITE + "/issues/"
vcsUrl = REPO
licenses = [LICENSE]
labels = LABELS
publicDownloadNumbers = true

githubRepo = GITHUB
githubReleaseNotesFile = 'README.md'
Expand Down
22 changes: 22 additions & 0 deletions standalone.gradle
@@ -0,0 +1,22 @@
/** Apply from this file when developing IS to include it as local module in another project.
*
* Steps:
* 1/ In your app project, add the following to `settings.gradle`:
* ```groovy
* include ':is'
* project(':is').projectDir = new File(settingsDir, "../instantsearch-android/ui")
* include ':core'
* project(':core').projectDir = new File(settingsDir, "../instantsearch-android/core")
* ```
* 2/ In your app's build.gradle, add `implementation project(":is")`
* 3/ In InstantSearch modules `ui` and `core`, uncomment the first line of both build.gradle to apply standalone.gradle
*
* You should now be able to build your application with the local source of IS.
*/

buildscript {
apply from: '../libraries.gradle'
}
apply from: "../ext.gradle"
apply from: "../common.gradle"

18 changes: 11 additions & 7 deletions ui/build.gradle
@@ -1,18 +1,22 @@
//apply from: "../standalone.gradle" // Uncomment to use module in another project

ext {
DESC = "A library and widgets to build instant-search applications on Android."
BASENAME = 'instantsearch-android'
DESC = "A library and widgets to build instant-search applicattions on Android."
BASENAME = 'instantsearch-android-ui'
if (project.hasProperty("LABELS")) {
LABELS += "data-binding"
}
}

group = GROUP
version = VERSION

android.dataBinding.enabled true

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':core')
api project(':core')

implementation libraries.glide
implementation libraries.recyclerview
implementation libraries.constraint_layout
}
}

apply from: '../release.gradle'

0 comments on commit a858eec

Please sign in to comment.