Java 声纳属性文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21934591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 11:28:34  来源:igfitidea点击:

Sonar properties files

javasonarqube

提问by Biscuit128

I have a project that has the following package structure

我有一个具有以下包结构的项目

src/main/proj
    -com.company.package
        -appName
            -morepackages

        -appVersion2
            -morepackages

sonar-runner.properties
sonarBuild.sh
sonar-runner-project2.properties
sonarBuildProject2.sh

As it stands, with the default properties file i can run the sonar report and it will generate a review for the whole project

就目前而言,使用默认属性文件,我可以运行声纳报告,它将为整个项目生成评论

sonar.projectKey=KEY
sonar.projectName=PROJNAME
sonar.projectVersion=1.0

sonar.host.url=someurl

#Path for sonar sources
sonar.sources=src/main/java

#Path for libraries
sonar.libraries=target/lib/*.jar

#Path for binaries
sonar.binaries=target/classes

#--------Default database
sonar.jdbc.url=someurl
sonar.jdbc.driver=com.mysql.jdbc.Driver

#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar

#----- Default directory layout
sonar.java.source=1.6
sonar.java.target=1.6

sonar.sourceEncoding=UTF-8

Ideally however I would like to separate the two reports so i have one for the original package and one for the appVersion2 package. Now - as mentioned above I have created a separate properties file for each. Should i just point sonar.sourcesto the respective packages for each job to analyse or is there a better way to do this all in one property file?

但理想情况下,我想将两份报告分开,因此我有一份用于原始包,一份用于 appVersion2 包。现在 - 如上所述,我为每个文件创建了一个单独的属性文件。我应该只指向sonar.sources每个作业的相应包进行分析,还是有更好的方法在一个属性文件中完成所有操作?

Thanks

谢谢

EDIT

编辑

My multi module attempt properties file looks as follows

我的多模块尝试属性文件如下所示

sonar.projectKey=rootkey
sonar.projectName=rootname
sonar.projectVersion=1.0
sonar.host.url=rooturl
sonar.sources=src/main/java/
sonar.libraries=target/lib/*.jar
sonar.modules=module1,module2
sonar.sourceEncoding=UTF-8

#----- Global database settings
sonar.jdbc.username=user
sonar.jdbc.password=pass

sonar.java.source=1.7
sonar.java.target=1.7


#--------Default database
sonar.jdbc.url=url
sonar.jdbc.driver=com.mysql.jdbc.Driver


module1.sonar.projectName=proja
module2.sonar.projectName=projb

module1.sonar.projectKey=projakey
module2.sonar.projectKey=projbkey

#Path for sonar sources
module1.sonar.sources=src/main/java/app1code
module2.sonar.sources=src/main/java/app2code

#Path for binaries
module1.sonar.binaries=target/classes/app1binaries
module2.sonar.binaries=target/classes/app2binaries

I get an error in the output saying....

我在输出中收到一个错误说....

Exception in thread "main" org.sonar.runner.RunnerException: org.sonar.runner.RunnerException: The base directory of the module 'module1' does not exist: patthtoapp/module1
    at org.sonar.runner.Runner.delegateExecution(Runner.java:288)
    at org.sonar.runner.Runner.execute(Runner.java:151)
    at org.sonar.runner.Main.execute(Main.java:84)
    at org.sonar.runner.Main.main(Main.java:56)
Caused by: org.sonar.runner.RunnerException: The base directory of the module 'module1' does not exist: pathtoapp/module1
    at org.sonar.runner.internal.batch.SonarProjectBuilder.setProjectBaseDir(SonarProjectBuilder.java:279)
    at org.sonar.runner.internal.batch.SonarProjectBuilder.loadChildProject(SonarProjectBuilder.java:191)
    at org.sonar.runner.internal.batch.SonarProjectBuilder.defineChildren(SonarProjectBuilder.java:169)
    at org.sonar.runner.internal.batch.SonarProjectBuilder.generateProjectDefinition(SonarProjectBuilder.java:122)
    at org.sonar.runner.internal.batch.Launcher.execute(Launcher.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.sonar.runner.Runner.delegateExecution(Runner.java:285)

采纳答案by Rapha?l

You have to specify the projectBaseDirif the module name doesn't match you module directory.

projectBaseDir如果模块名称与您的模块目录不匹配,您必须指定。

Since both your module are located in ".", you can simply add the following to your sonar-project properties:

由于您的模块都位于“.”中,您只需将以下内容添加到声纳项目属性中:

module1.sonar.projectBaseDir=.
module2.sonar.projectBaseDir=.

Sonar will handle your modules as components of the project:

Sonar 会将您的模块作为项目的组件进行处理:

Result of Sonar analysis

声纳分析结果

EDIT

编辑

If both of your modules are located in the same source directory, define the same source folder for both and exclude the unwanted packages with sonar.exclusions:

如果您的两个模块位于同一源目录中,请为两者定义相同的源文件夹并使用以下命令排除不需要的包sonar.exclusions

module1.sonar.sources=src/main/java
module1.sonar.exclusions=app2code/**/*

module2.sonar.sources=src/main/java
module2.sonar.exclusions=app1code/**/*

More details about file exclusion

有关文件排除的更多详细信息

回答by vzamanillo

You can define a Multi-module project structure, then you can set the configuration for sonar in one properties file in the root folder of your project, (Way #1)

您可以定义一个多模块项目结构,然后您可以在项目根文件夹中的一个属性文件中设置声纳的配置,( Way #1)

回答by amigo21

Do the build job on Jenkins first without Sonar configured. Then add Sonar, and run a build job again. Should fix the problem

在没有配置声纳的情况下,首先在 Jenkins 上执行构建工作。然后添加声纳,并再次运行构建作业。应该解决问题