Skip to content

Commit

Permalink
separate build scripts.
Browse files Browse the repository at this point in the history
move javadocJar task def.

add sonatype upload logic.

fix: properties file.

comment out for javadocJar.
  • Loading branch information
wasnot committed Feb 22, 2021
1 parent 7639ef7 commit 606d047
Show file tree
Hide file tree
Showing 17 changed files with 322 additions and 269 deletions.
11 changes: 10 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ commands:
- restore_cache:
name: Restoring build gradle cache
key: jars-{{ checksum "build.gradle" }}-{{ checksum "core/build.gradle" }}-{{ checksum "core/version" }}-{{ checksum "inappmessaging/build.gradle" }}-{{ checksum "inappmessaging/version" }}-{{ checksum "notifications/build.gradle" }}-{{ checksum "notifications/version" }}-{{ checksum "variables/build.gradle" }}-{{ checksum "variables/version" }}-{{ checksum "visualtracking/build.gradle" }}-{{ checksum "visualtracking/version" }}-{{ checksum "examples/sample_java/build.gradle" }}-{{ checksum "examples/sample_kotlin/build.gradle" }}-{{ checksum "gradle-plugin/build.gradle" }}

- run:
name: Decrypt properties
# encrypt to update(OpenSSL 1.1.1):
# openssl aes-256-cbc -e -md sha512 -pbkdf2 -iter 100000 -salt -in buildscripts/gradle.properties -out buildscripts/encrypted.properties -k $ENCRYPT_KEY
command: |
mkdir -p ~/.gradle
openssl aes-256-cbc -d -md sha512 -pbkdf2 -iter 100000 -salt -in buildscripts/encrypted.properties -k $ENCRYPT_KEY >> ~/.gradle/gradle.properties
- run:
name: Decrypt GPG key
command: echo "$GPG_KEY" | base64 -d > secret-keys.gpg
- run:
name: Download Dependencies
command: ./gradlew androidDependencies
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ lint/tmp/


# macOS
.DS_Store
.DS_Store

secret-keys.gpg
222 changes: 25 additions & 197 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// for upload maven repo
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// for apply karte plugin to example project
classpath 'io.karte.android:karte-gradle-plugin'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

plugins {
id 'org.jetbrains.dokka' version '0.10.1'
id 'com.jfrog.bintray' version '1.8.5'
id 'maven-publish'
id 'io.codearte.nexus-staging' version '0.22.0'
}

allprojects {
Expand All @@ -32,211 +35,36 @@ allprojects {
configure(subprojects.findAll { !it.name.startsWith("sample_") }) {
println "configure libraries: ${project.name}"

apply plugin: 'org.jetbrains.dokka'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'

group 'io.karte.android'
version project.file('version').getText('UTF-8').trim()
def gitUrl = 'https://github.com/plaidev/karte-android-sdk'
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 {
developer {
id "kartetaro"
name "Taro Karte"
email "[email protected]"
}
}
scm {
connection 'scm:git:git://github.com/plaidev/karte-android-sdk.git'
developerConnection 'scm:git:ssh://github.com/plaidev/karte-android-sdk.git'
url gitUrl
}
apply from: '../buildscripts/projectDokka.gradle'
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
outputFormat = 'javadoc'
outputDirectory = "$buildDir/javadoc"
}
def releaseNote = 'https://developers.karte.io/docs/release-note-android-sdk'

task sourcesJar(type: Jar) {
from "${projectDir}/src/main/java"
classifier = 'sources'
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
classifier = 'javadoc'
from "$buildDir/javadoc"
}

publishing {
publications {
maven(MavenPublication) {
artifact sourcesJar
artifact source: file("${project.buildDir}/outputs/aar/${project.name}-release.aar")
groupId group
artifactId project.name
version version
apply from: '../buildscripts/projectJacoco.gradle'

versionMapping {
usage('java-implementation') {
fromResolutionOf('runtimeClasspath')
}
}

pom.withXml {
def root = asNode()
root.appendNode('description', "${project.name} module for KARTE SDK")
def dependencies = root.appendNode("dependencies")
configurations.implementation.dependencies.each {
if (it.group == null || it.name == null || it.version == null || it.name == "unspecified") return
def node = dependencies.appendNode("dependency")
node.appendNode("groupId", it.group)
node.appendNode("artifactId", it.name)
node.appendNode("version", it.version)
}
root.children().last() + pomConfig
}
}
}
}
apply from: '../buildscripts/projectMaven.gradle'
apply from: '../buildscripts/projectMavenAndroid.gradle'
apply from: '../buildscripts/projectBintray.gradle'
apply from: '../buildscripts/projectSonatype.gradle'
publishMavenPublicationToMavenLocal.dependsOn "assembleRelease"

bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
publish = true

pkg {
repo = 'maven'
name = "$group:${project.name}"
userOrg = 'plaidev'
licenses = ['Apache-2.0']
vcsUrl = gitUrl + '.git'
version {
name = project.version
released = new Date()
vcsTag = project.version
desc = releaseNote
}
}
publications = ['maven']
}

dokka {
Set<ProjectDependency> deps =
project.configurations.collectMany {
it.allDependencies
}.findAll {
it instanceof ProjectDependency
}

configuration {
deps.collect { p ->
sourceRoot {
path = "${p.getDependencyProject().projectDir.toString()}/src/main/java"
}
}
}
}

apply plugin: "jacoco"

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}

jacoco {
toolVersion = "0.8.5"
}

task jacocoTestReport(
type: JacocoReport,
dependsOn: "testDebugUnitTest",
group: "verification"
) {
reports {
xml.enabled = true
html.enabled = true
}
getSourceDirectories().from = "${projectDir}/src/main/java"
getClassDirectories().from = files(
fileTree(dir: "${buildDir}/tmp/kotlin-classes/debug"),
fileTree(dir: "${buildDir}/intermediates/javac/debug/classes/"))

getExecutionData().from = "${buildDir}/jacoco/testDebugUnitTest.exec"
}

}

task clean(type: Delete) {
delete rootProject.buildDir
}

configurations {
ktlint
}

dependencies {
ktlint "com.pinterest:ktlint:0.36.0"
// additional 3rd party ruleset(s) can be specified here
// just add them to the classpath (e.g. ktlint 'groupId:artifactId:version') and
// ktlint will pick them up
}

task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "--android", "--color", "--editorconfig=.editorconfig", "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/reports/ktlint-results.xml", "**/src/**/*.kt"
// to generate report in checkstyle format prepend following args:
// "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
// see https://github.com/pinterest/ktlint#usage for more
}
//check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "-F", "**/src/**/*.kt --editorconfig=.editorconfig"
}

dokka {
tasks.dokka.logging.captureStandardOutput LogLevel.LIFECYCLE
subProjects = ["core", "inappmessaging", "notifications", "variables", "visualtracking"]
outputDirectory = "${buildDir}/dokka"
outputFormat = "html"
configuration {
reportUndocumented = true
}
}

task generateDocs(type: Exec, group: 'documentation') {
subprojects.findAll {it.tasks.findByPath('dokka')}.each { dependsOn("${it.name}:dokka") }
commandLine "ruby", "scripts/publish_docs.rb"
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
doLast {
println(standardOutput.toString())
}
}

apply plugin: "jacoco"
apply from: 'buildscripts/ktlint.gradle'
apply from: 'buildscripts/dokka.gradle'
apply from: 'buildscripts/jacoco.gradle'

jacoco {
toolVersion = "0.8.5"
}

task jacocoMerge(
type: JacocoMerge,
group: "verification",
dependsOn: ["core:jacocoTestReport", "inappmessaging:jacocoTestReport", "notifications:jacocoTestReport", "variables:jacocoTestReport", "visualtracking:jacocoTestReport"]
) {
gradle.afterProject { project, _ ->
if (project.rootProject != project && project.plugins.hasPlugin('jacoco')) {
executionData "${project.buildDir}/jacoco/testDebugUnitTest.exec"
}
}
nexusStaging {
packageGroup ='io.karte.android'
username = ossrhUsername
password = ossrhPassword
}
2 changes: 2 additions & 0 deletions buildscripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gradle.properties

21 changes: 21 additions & 0 deletions buildscripts/dokka.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
dokka {
tasks.dokka.logging.captureStandardOutput LogLevel.LIFECYCLE
subProjects = ["core", "inappmessaging", "notifications", "variables", "visualtracking"]
outputDirectory = "${buildDir}/dokka"
outputFormat = "html"
configuration {
reportUndocumented = true
}
}

task generateDocs(type: Exec, group: 'documentation') {
subprojects.findAll { it.tasks.findByPath('dokka') }.each { dependsOn("${it.name}:dokka") }
commandLine "ruby", "scripts/publish_docs.rb"
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
doLast {
println(standardOutput.toString())
}
}
Binary file added buildscripts/encrypted.properties
Binary file not shown.
17 changes: 17 additions & 0 deletions buildscripts/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apply plugin: "jacoco"

jacoco {
toolVersion = "0.8.5"
}

task jacocoMerge(
type: JacocoMerge,
group: "verification",
dependsOn: ["core:jacocoTestReport", "inappmessaging:jacocoTestReport", "notifications:jacocoTestReport", "variables:jacocoTestReport", "visualtracking:jacocoTestReport"]
) {
gradle.afterProject { project, _ ->
if (project.rootProject != project && project.plugins.hasPlugin('jacoco')) {
executionData "${project.buildDir}/jacoco/testDebugUnitTest.exec"
}
}
}
28 changes: 28 additions & 0 deletions buildscripts/ktlint.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
configurations {
ktlint
}

dependencies {
ktlint "com.pinterest:ktlint:0.36.0"
// additional 3rd party ruleset(s) can be specified here
// just add them to the classpath (e.g. ktlint 'groupId:artifactId:version') and
// ktlint will pick them up
}

task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "--android", "--color", "--editorconfig=.editorconfig", "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/reports/ktlint-results.xml", "**/src/**/*.kt"
// to generate report in checkstyle format prepend following args:
// "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
// see https://github.com/pinterest/ktlint#usage for more
}
//check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "-F", "**/src/**/*.kt --editorconfig=.editorconfig"
}
35 changes: 35 additions & 0 deletions buildscripts/projectBintray.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'

publishing {
publications {
maven(MavenPublication) {
groupId group
artifactId project.name
version version

project.makePublication(it)
}
}
}

bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
publish = true

pkg {
repo = 'maven'
name = "$group:${project.name}"
userOrg = 'plaidev'
licenses = ['Apache-2.0']
vcsUrl = project.gitUrl + '.git'
version {
name = project.version
released = new Date()
vcsTag = project.version
desc = project.releaseNote
}
}
publications = ['maven']
}
Loading

0 comments on commit 606d047

Please sign in to comment.