简体   繁体   English

如何从基于gradle的项目中检索sonar-project-properties

[英]How to retrieve sonar-project-properties from gradle based project

current state 当前状态

I am currently working on a java application that is supposed to clone different projects locally and the generate the sonar-project.properties file to prepare for SonarQube analysis. 我目前正在开发一个Java应用程序,该应用程序应该在本地克隆不同的项目,并生成sonar-project.properties文件以准备进行SonarQube分析。

The application can do this for maven based projects by detecting the "pom.xml" file and getting the needed property eg "sonar.modules" from the tag in that file and writes them into the sonar-project.properties file of that project. 应用程序可以通过检测“ pom.xml”文件并从该文件中的标记获取所需的属性(例如“ sonar.modules”)并将其写入该项目的sonar-project.properties文件中,从而对基于Maven的项目执行此操作。

Question

Now I'm supposed to expand my program to analyze Gradle based projects. 现在,我应该扩展程序以分析基于Gradle的项目。 Since I have never worked with Gradle my question is where I can find the information I need in order to configure the sonar-project.properties file eg modules, sourceDirectory etc. correctly. 由于我从未与Gradle合作过,所以我的问题是,在哪里可以找到我所需的信息,以便正确配置sonar-project.properties文件,例如模块,sourceDirectory等。

This is my first SOF-question so please write a comment if you need any additional information. 这是我的第一个SOF问题,因此,如果您需要任何其他信息,请写评论。

Thanks in Advance. 提前致谢。

If you are fully using gradle to build you project this will be quiet easy and handy to achieve. 如果您完全使用gradle来构建项目,那么这将很容易实现。 most important part is that you take a close look at the gradle plugin documentation and examples - https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle 最重要的是,你需要在gradle这个插件的文档和例子仔细看- https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle

i will add here a short gradle build script, based on a start.spring.io project with gradle. 我将在此处添加一个简短的gradle构建脚本,该脚本基于带有gradle的start.spring.io项目。 When you call gradle build sonarqube this will 当您致电gradle build sonarqube这将

  • build your application 建立你的应用程序
  • run your tests, with coverage as the jacoco plugin is applied too 运行测试,涵盖范围也适用于jacoco插件
  • upload everything to the specified sonar server 将所有内容上传到指定的声纳服务器

example: 例:

buildscript {
    ext {
        springBootVersion = '2.0.1.RELEASE'
    }
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2'
        classpath "org.ajoberstar:grgit:2.2.0"
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'jacoco'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.sonarqube'

group = 'net.gradle.testing'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

sonarqube {
    properties {
        System.setProperty('sonar.host.url', 'host URL')
    }
}

But as already stated, to set special properties, or how the Proejct key and name is set, you best check the documentation of the scanner :D 但是,如上所述,要设置特殊属性或如何设置Proejct键和名称,最好检查扫描仪的文档:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM