You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

206 lines
7.8 KiB

/*
* Copyright 2016 straightway
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
buildscript {
ext.kotlin_version = '1.+'
ext.uploadToRepository = false
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.1'
classpath 'org.jmailen.gradle:kotlinter-gradle:2.1.2'
}
}
group 'straightway'
apply from: 'version.gradle'
apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: 'jacoco'
apply plugin: 'org.jmailen.kotlinter'
tasks.idea.dependsOn cleanIdea
check.dependsOn jacocoTestCoverageVerification
jacocoTestCoverageVerification.dependsOn test
if (idea.project != null) {
idea.project.ipr {
withXml { provider ->
def inspectionManager = provider.asNode().appendNode('component', [name: 'InspectionProjectProfileManager'])
def profile = inspectionManager.appendNode('profile', [version: '1.0'])
profile.appendNode('option', [name: 'myName', value: 'Project Default'])
def classInspection = profile.appendNode('inspection_tool', [class : 'ClassName',
enabled : 'true',
level : 'WEAK WARNING',
enabled_by_default: 'true'])
classInspection.appendNode('option', [name: 'namePattern', value: '[A-Z][_ A-Za-z\\d]*'])
def funInspection = profile.appendNode('inspection_tool', [class : 'FunctionName',
enabled : 'true',
level : 'WEAK WARNING',
enabled_by_default: 'true'])
funInspection.appendNode('option', [name: 'namePattern', value: '[a-z][_A-Za-z\\d]*'])
def testFunInspection = profile.appendNode('inspection_tool', [class : 'TestFunctionName',
enabled : 'true',
level : 'WEAK WARNING',
enabled_by_default: 'true'])
testFunInspection.appendNode('option', [name: 'namePattern', value: '.*'])
profile.appendNode('inspection_tool', [class : 'RemoveRedundantBackticks',
enabled : 'false',
level : 'WARNING',
enabled_by_default: 'false'])
def copyrightManager = provider.asNode().appendNode('component', [name: 'CopyrightManager', default: 'Apache License'])
def copyright = copyrightManager.appendNode('copyright')
copyright.appendNode('option', [name: 'myName', value: 'Apache License'])
copyright.appendNode('option', [name: 'notice', value: 'Copyright 2016 straightway\n\n Licensed under the Apache License, Version 2.0 (the "License");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an "AS IS" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.'])
}
}
}
repositories {
mavenCentral()
maven { url "https://pages.codeberg.org/straightway/repo" }
jcenter()
}
static def junit5(part) { return "org.junit.jupiter:junit-jupiter-${part}:5.+".toString() }
@SuppressWarnings("GrMethodMayBeStatic")
def kotlin(part) { return "org.jetbrains.kotlin:kotlin-${part}:$kotlin_version".toString() }
static def mockito() { return "org.mockito:mockito-core:2.+" }
static def mockitoKotlin() { return 'com.nhaarman:mockito-kotlin:1.+' }
static def koin() { return 'org.koin:koin-core:0.+' }
def straightway(lib) {
return findProject(":${lib}") ?: "straightway:${lib.replaceAll(':', '-')}:${version}".toString()
}
def straightway(lib, version) {
return findProject(":${lib}") ?: "straightway:${lib.replaceAll(':', '-')}:${version}".toString()
}
dependencies {
compile kotlin("stdlib-jdk8")
testCompile junit5("api")
testRuntime junit5("engine")
}
def findParentPath(String dirToFind) {
def pathToCheck = project.projectDir
while (pathToCheck != '/') {
def buildTemplatesDirToCheck = "${pathToCheck}/${dirToFind}".toString()
if (new File(buildTemplatesDirToCheck).isDirectory()) {
return buildTemplatesDirToCheck
}
pathToCheck = file(pathToCheck).parent
}
return null
}
task refreshBuild(group: 'build setup') {
doLast {
def buildTemplatesDir = findParentPath("buildTemplates")
new File(buildTemplatesDir).eachFile {
def fileToRefresh = new File("${project.projectDir}/${it.name}")
if (fileToRefresh.exists()) {
def srcFile = "${buildTemplatesDir}/${it.name}".toString()
copy {
from srcFile
into project.projectDir
}
}
}
}
}
apply from: 'projectSpecific.gradle'
def repoPath = findParentPath("pages/repo")
if ((repoPath != null) && ext.uploadToRepository) {
uploadArchives {
repositories {
mavenDeployer {
pom.artifactId = project.path.substring(1).replaceAll(':', '-')
repository(url: "file://" + file(repoPath))
}
}
}
}
test {
useJUnitPlatform()
}
jacoco {
toolVersion = "0.+"
}
jacocoTestReport {
afterEvaluate {
getClassDirectories().from(files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/Main*'])
}))
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
element = 'SOURCEFILE'
excludes = ['**/Main*.kt', '**/*Samples.kt', '**/*_NOCOVERAGE.kt', '**/KoinContext.kt', '**/Context.kt']
limit {
counter = 'LINE'
minimum = 0.70
}
}
}
}
test {
jacoco {
destinationFile = file("${buildDir}/jacoco/test.exec")
}
}
compileKotlin {
kotlinOptions {
allWarningsAsErrors = true
jvmTarget = "1.6"
}
}
compileTestKotlin {
kotlinOptions {
allWarningsAsErrors = true
jvmTarget = "1.6"
}
}
detekt {
config = files("$project.projectDir/detekt-config.yml".toString())
filters = ".*/out/.*"
}
kotlinter {
continuationIndentSize = 4
disabledRules = ['final-newline']
}