如何为多种语言(Kotlin 和 Java)配置声纳 fastlane?

问题描述 投票:0回答:1

我正在为我的一个 Android 项目设置 Sonarqube,该项目是 Kotlin 和 Java 的混合体。 我用 fastlane 配置声纳:

desc "Run SonarQube analysis"
  lane :sonar_scanner do
    sonar(
        project_key: "com.****************.main.dev",
        project_version: "1.0",
        project_name: "************",
        project_language: "java , kotlin",
        sources_path: "absolute_path_to_/src/main",
        sonar_login: "****************************",
        sonar_url: "*********************************",
    )
  end

输出: - 但 Sonarqube 仅分析 kotlin 和 xml 文件

任何人都可以建议如何为多种语言(java 和 kotlin)配置它吗?

java android kotlin sonarqube fastlane
1个回答
0
投票

总体配置:

plugins {
    id 'java'
    id 'jacoco'
    id "org.sonarqube" version "4.0.0.2929"
}

allprojects {
    version = '1.0.2'
    group = 'org.sonarqube.sample'

    repositories {
        mavenCentral()
    }
}

subprojects {
    apply plugin: 'org.sonarqube'
    sonar {
        properties {
            property 'sonar.coverage.jacoco.xmlReportPaths', "$projectDir.parentFile.path/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
        }
    }

    tasks.withType(Test).configureEach {
        useJUnitPlatform()
    }
}

apply from: "$project.rootDir/sonar.gradle"

// See here for more info: https://docs.gradle.org/6.4-rc-1/samples/sample_jvm_multi_project_with_code_coverage.html
//
// task to gather code coverage from multiple subprojects
// NOTE: the `JacocoReport` tasks do *not* depend on the `test` task by default. Meaning you have to ensure
// that `test` (or other tasks generating code coverage) run before generating the report.
// You can achieve this by calling the `test` lifecycle task manually
// $ ./gradlew test codeCoverageReport
tasks.register("codeCoverageReport", JacocoReport) {
    // If a subproject applies the 'jacoco' plugin, add the result it to the report
    subprojects { subproject ->
        subproject.plugins.withType(JacocoPlugin).configureEach {
            subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).configureEach { testTask ->
                //the jacoco extension may be disabled for some projects
                if (testTask.extensions.getByType(JacocoTaskExtension).isEnabled()) {
                    sourceSets subproject.sourceSets.main
                    executionData(testTask)
                } else {
                    logger.warn('Jacoco extension is disabled for test task \'{}\' in project \'{}\'. this test task will be excluded from jacoco report.',testTask.getName(),subproject.getName())
                }
            }

            // To automatically run `test` every time `./gradlew codeCoverageReport` is called,
            // you may want to set up a task dependency between them as shown below.
            // Note that this requires the `test` tasks to be resolved eagerly (see `forEach`) which
            // may have a negative effect on the configuration time of your build.
            subproject.tasks.matching({ t -> t.extensions.findByType(JacocoTaskExtension) }).forEach {
                rootProject.tasks.codeCoverageReport.dependsOn(it)
            }
        }
    }

    // enable the different report types (html, xml, csv)
    reports {
        xml.required = true
        html.required = true
        html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
    }
}

这是示例示例

© www.soinside.com 2019 - 2024. All rights reserved.