167 lines
5.6 KiB
Groovy
167 lines
5.6 KiB
Groovy
buildscript {
|
|
repositories {
|
|
maven { url "https://plugins.gradle.org/m2" }
|
|
}
|
|
dependencies {
|
|
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.5.1"
|
|
}
|
|
}
|
|
|
|
def getServerProjectSources
|
|
def getAndroidProjectSources
|
|
|
|
apply from: "$buildScriptsDir/gradle/commonStaticAnalysis.gradle"
|
|
|
|
gradle.projectsEvaluated {
|
|
|
|
tasks.withType(JavaCompile) {
|
|
options.compilerArgs <<
|
|
"-Xlint:cast" <<
|
|
"-Xlint:divzero" <<
|
|
"-Xlint:empty" <<
|
|
"-Xlint:deprecation" <<
|
|
"-Xlint:finally" <<
|
|
"-Xlint:overrides" <<
|
|
"-Xlint:path" <<
|
|
"-Werror"
|
|
}
|
|
|
|
def excludes = rootProject.extensions.findByName("staticAnalysisExcludes")
|
|
|
|
def androidSources = getAndroidProjectSources(excludes)
|
|
def androidStaticAnalysisTasks = getStaticAnalysisTaskNames(true, androidSources, null)
|
|
def androidIdeaFormatTask = getIdeaFormatTask(true, androidSources)
|
|
|
|
task staticAnalysisWithFormatting {
|
|
androidStaticAnalysisTasks.each { task ->
|
|
tasks.findByName(task)?.mustRunAfter(androidIdeaFormatTask)
|
|
}
|
|
dependsOn androidIdeaFormatTask
|
|
dependsOn androidStaticAnalysisTasks
|
|
doFirst {
|
|
generateReport(true)
|
|
}
|
|
}
|
|
|
|
task staticAnalysis {
|
|
dependsOn androidStaticAnalysisTasks
|
|
doFirst {
|
|
generateReport(true)
|
|
}
|
|
}
|
|
|
|
def serverStaticAnalysisTasks = getStaticAnalysisTaskNames(false, getServerProjectSources(excludes), null)
|
|
def serverIdeaFormatTask = getIdeaFormatTask(false, getServerProjectSources(excludes))
|
|
|
|
task serverStaticAnalysisWithFormatting {
|
|
serverStaticAnalysisTasks.each { task ->
|
|
tasks.findByName(task)?.mustRunAfter(serverIdeaFormatTask)
|
|
}
|
|
dependsOn serverIdeaFormatTask
|
|
dependsOn serverStaticAnalysisTasks
|
|
doFirst {
|
|
generateReport(false)
|
|
}
|
|
}
|
|
|
|
task serverStaticAnalysis {
|
|
dependsOn serverStaticAnalysisTasks
|
|
doFirst {
|
|
generateReport(false)
|
|
}
|
|
}
|
|
|
|
subprojects { subproject ->
|
|
if (subproject.plugins.hasPlugin("com.android.application")) {
|
|
subproject.android {
|
|
lintOptions.abortOnError = false
|
|
lintOptions.checkAllWarnings = true
|
|
lintOptions.warningsAsErrors = false
|
|
lintOptions.xmlReport = true
|
|
lintOptions.xmlOutput = file "$rootProject.buildDir/reports/lint_report.xml"
|
|
lintOptions.htmlReport = false
|
|
lintOptions.lintConfig = file "$buildScriptsDir/lint/lint.xml"
|
|
lintOptions.checkDependencies true
|
|
lintOptions.disable 'MissingConstraints', 'VectorRaster'
|
|
|
|
applicationVariants.all { variant ->
|
|
task("staticAnalysis${variant.name.capitalize()}") {
|
|
dependsOn getStaticAnalysisTaskNames(true, androidSources, variant)
|
|
doFirst { generateReport(true) }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
def regex = ~':detekt$'
|
|
tasks.forEach { task ->
|
|
if (!task.name.contains(":libs") && task.path =~ regex) {
|
|
task.exclude '**/test/**'
|
|
task.exclude 'resources/'
|
|
task.exclude 'build/'
|
|
task.exclude 'tmp/'
|
|
|
|
task.jvmTarget = "1.8"
|
|
}
|
|
}
|
|
|
|
detekt {
|
|
config = files("$buildScriptsDir/kotlin/detekt-config.yml")
|
|
|
|
reports {
|
|
txt.enabled = false
|
|
html.enabled = false
|
|
xml {
|
|
enabled = true
|
|
destination = file("${rootProject.buildDir}/reports/kotlin-detekt-${subproject.name}.xml")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
getServerProjectSources = { excludes ->
|
|
def sources = new ArrayList<String>()
|
|
def sourcesDirectory = new File(project.projectDir.path, 'src')
|
|
|
|
for (def sourceFlavorDirectory : sourcesDirectory.listFiles()) {
|
|
def javaSourceDirectory = new File(sourceFlavorDirectory.path, 'java')
|
|
def kotlinSourceDirectory = new File(sourceFlavorDirectory.path, 'kotlin')
|
|
|
|
if (javaSourceDirectory.exists() && javaSourceDirectory.isDirectory()) {
|
|
sources.add(javaSourceDirectory.absolutePath)
|
|
}
|
|
if (kotlinSourceDirectory.exists() && kotlinSourceDirectory.isDirectory()) {
|
|
sources.add(kotlinSourceDirectory.absolutePath)
|
|
}
|
|
}
|
|
return sources
|
|
}
|
|
|
|
getAndroidProjectSources = { excludes ->
|
|
def sources = new ArrayList<String>()
|
|
for (def project : rootProject.subprojects) {
|
|
if (!project.subprojects.isEmpty() || (excludes != null && excludes.contains(project.path))) {
|
|
continue
|
|
}
|
|
|
|
def sourcesDirectory = new File(project.projectDir.path, 'src')
|
|
if (!sourcesDirectory.exists() || !sourcesDirectory.isDirectory()) {
|
|
continue
|
|
}
|
|
|
|
for (def sourceFlavorDirectory : sourcesDirectory.listFiles()) {
|
|
def javaSourceDirectory = new File(sourceFlavorDirectory.path, 'java')
|
|
def kotlinSourceDirectory = new File(sourceFlavorDirectory.path, 'kotlin')
|
|
|
|
if (javaSourceDirectory.exists() && javaSourceDirectory.isDirectory()) {
|
|
sources.add(javaSourceDirectory.absolutePath)
|
|
}
|
|
if (kotlinSourceDirectory.exists() && kotlinSourceDirectory.isDirectory()) {
|
|
sources.add(kotlinSourceDirectory.absolutePath)
|
|
}
|
|
}
|
|
}
|
|
return sources
|
|
}
|