From 8f65b376056b1beffa9095036916dcc2d754f0e4 Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Sat, 6 Oct 2018 13:37:12 +0200 Subject: [PATCH] Add common configuration for kotlin modules. --- .circleci/config.yml | 2 +- build.gradle | 4 ++ cache/build.gradle | 35 +----------- domain/build.gradle | 35 +----------- gradle_scripts/kotlin-module-bootstrap.gradle | 53 +++++++++++++++++++ subsonic-api/build.gradle | 37 +------------ 6 files changed, 61 insertions(+), 105 deletions(-) create mode 100644 gradle_scripts/kotlin-module-bootstrap.gradle diff --git a/.circleci/config.yml b/.circleci/config.yml index fa7fd824..c9002819 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,7 +25,7 @@ jobs: - run: name: unit-tests command: | - ./gradlew :subsonic-api:test :cache:test :subsonic-api-image-loader:testDebugUnitTest :ultrasonic:testDebugUnitTest + ./gradlew ciTest :ultrasonic:testDebugUnitTest ./gradlew jacocoFullReport bash <(curl -s https://codecov.io/bash) - run: diff --git a/build.gradle b/build.gradle index abcee58c..ac600b4d 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,10 @@ buildscript { apply from: 'dependencies.gradle' + ext.bootstrap = [ + kotlinModule : "${project.rootDir}/gradle_scripts/kotlin-module-bootstrap.gradle", + ] + repositories { jcenter() google() diff --git a/cache/build.gradle b/cache/build.gradle index 57cecf59..4d5d617a 100644 --- a/cache/build.gradle +++ b/cache/build.gradle @@ -1,11 +1,7 @@ -apply plugin: 'java-library' -apply plugin: 'kotlin' -apply plugin: 'jacoco' -apply from: '../gradle_scripts/code_quality.gradle' +apply from: bootstrap.kotlinModule dependencies { api project(':domain') - api other.kotlinStdlib api other.twitterSerial testImplementation testing.junit @@ -15,32 +11,3 @@ dependencies { testImplementation testing.mockitoKotlin testImplementation testing.kluent } - -jacoco { - toolVersion(versions.jacoco) -} - -ext { - jacocoExclude = [] -} - -jacocoTestReport { - reports { - html.enabled true - csv.enabled false - xml.enabled true - } - - afterEvaluate { - classDirectories = files(classDirectories.files.collect { - fileTree(dir: it, excludes: jacocoExclude) - }) - } -} - -test.finalizedBy jacocoTestReport -test { - jacoco { - excludes += jacocoExclude - } -} diff --git a/domain/build.gradle b/domain/build.gradle index cab611de..eefe64d0 100644 --- a/domain/build.gradle +++ b/domain/build.gradle @@ -1,38 +1,5 @@ -apply plugin: 'java-library' -apply plugin: 'kotlin' -apply plugin: 'jacoco' -apply from: '../gradle_scripts/code_quality.gradle' +apply from: bootstrap.kotlinModule dependencies { - api other.kotlinStdlib api other.semver } - -jacoco { - toolVersion(versions.jacoco) -} - -ext { - jacocoExclude = [] -} - -jacocoTestReport { - reports { - html.enabled true - csv.enabled false - xml.enabled true - } - - afterEvaluate { - classDirectories = files(classDirectories.files.collect { - fileTree(dir: it, excludes: jacocoExclude) - }) - } -} - -test.finalizedBy jacocoTestReport -test { - jacoco { - excludes += jacocoExclude - } -} diff --git a/gradle_scripts/kotlin-module-bootstrap.gradle b/gradle_scripts/kotlin-module-bootstrap.gradle new file mode 100644 index 00000000..31e2154c --- /dev/null +++ b/gradle_scripts/kotlin-module-bootstrap.gradle @@ -0,0 +1,53 @@ +apply plugin: 'java-library' +apply plugin: 'kotlin' +apply plugin: 'jacoco' +apply from: "${project.rootDir}/gradle_scripts/code_quality.gradle" + +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 + +sourceSets { + main.java.srcDirs += "${projectDir}/src/main/kotlin" + test.java.srcDirs += "${projectDir}/src/test/kotlin" + test.java.srcDirs += "${projectDir}/src/integrationTest/kotlin" + test.resources.srcDirs += "${projectDir}/src/integrationTest/resources" +} + +dependencies { + api other.kotlinStdlib +} + +jacoco { + toolVersion(versions.jacoco) +} + +ext { + // override it in the module + jacocoExclude = [] +} + +jacocoTestReport { + reports { + html.enabled true + csv.enabled false + xml.enabled true + } + + afterEvaluate { + classDirectories = files(classDirectories.files.collect { + fileTree(dir: it, excludes: jacocoExclude) + }) + } +} + +test.finalizedBy jacocoTestReport +test { + jacoco { + excludes += jacocoExclude + } +} + +task("ciTest", dependsOn: "test") { + group = "Verification" + description = "Special task for CI that calls all tests in pure kotlin modules" +} diff --git a/subsonic-api/build.gradle b/subsonic-api/build.gradle index 78f37860..45b205a1 100644 --- a/subsonic-api/build.gradle +++ b/subsonic-api/build.gradle @@ -1,16 +1,6 @@ -apply plugin: 'kotlin' -apply plugin: 'java-library' -apply plugin: 'jacoco' -apply from: '../gradle_scripts/code_quality.gradle' - -sourceSets { - main.java.srcDirs += "${projectDir}/src/main/kotlin" - test.java.srcDirs += "${projectDir}/src/integrationTest/kotlin" - test.resources.srcDirs += "${projectDir}/src/integrationTest/resources" -} +apply from: bootstrap.kotlinModule dependencies { - api other.kotlinStdlib api other.retrofit api other.jacksonConverter api other.koinCore @@ -31,10 +21,6 @@ dependencies { testImplementation testing.apacheCodecs } -jacoco { - toolVersion(versions.jacoco) -} - ext { // Excluding data classes jacocoExclude = [ @@ -42,24 +28,3 @@ ext { '**/di/**' ] } - -jacocoTestReport { - reports { - html.enabled true - csv.enabled false - xml.enabled true - } - - afterEvaluate { - classDirectories = files(classDirectories.files.collect { - fileTree(dir: it, excludes: jacocoExclude) - }) - } -} - -test.finalizedBy jacocoTestReport -test { - jacoco { - excludes += jacocoExclude - } -}