使用 gradle/sonar/Jacoco 排除项目 [英] Project exclude with gradle / sonar / Jacoco

查看:32
本文介绍了使用 gradle/sonar/Jacoco 排除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我们有一个包含 90 多个子项目的构建,其中经常出现目录与项目名称不完全匹配的情况.在某些情况下,我们有空的无项目父目录,而在其他情况下,名称与目录结构不匹配.例如,项目 abc-toaster 的子目录可能仅命名为 toaster.错误是:

So we have a build with 90+ sub-projects where it's often the case that the directory doesn't perfectly match the project name. In some cases we have empty project-less parent directories and in others the name just doesn't match the directory structure. For example, the sub-directory for project abc-toaster might be named just toaster. The error is:

模块':commons:thingamajig'的基本目录不存在:/dev/abc/:commons:thingamajig

The base directory of the module ':commons:thingamajig' does not exist:/dev/abc/:commons:thingamajig

...除了 commons/thingamajig 中没有 build.gradle我怎样才能让声纳解决这个问题?我试过了:

...except there is no build.gradle in commons/thingamajig How can I get Sonar around this? I've tried:

  1. commons/thingamajig 中放置一个空的虚拟 build.gradle - 没有骰子.同样的错误.
  2. 如下所述设置 someModule.sonar.projectBaseDir:声纳属性文件
  3. 运行完整的调试跟踪以查看弹出的内容.结果:没有什么明显的.
  1. Putting an empty dummy build.gradle in commons/thingamajig - No dice. Same error.
  2. Setting someModule.sonar.projectBaseDir as mentioned here: Sonar properties files
  3. Running a full debug trace to see what pops up. Result: Nothing obvious.

我在哪里解决这个问题?

Where am I hosing this up?

示例更新:

allprojects {
    sonarqube {
        file("$buildDir/classes").mkdirs();
        properties {
            property "sonar.exclusions", ["**/generated-src/**"]
            property "sonar.projectName", "ABC"
            property "sonar.projectKey", "$project.group:$project.name"
            property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
            property "sonar.projectBaseDir", "${project.rootDir}"
        }
    }
}

以上给出:

Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.batch.scan.ProjectLock
...
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.api.batch.bootstrap.ProjectReactor
...
Caused by: java.lang.IllegalStateException: The base directory of the module ':commons:thingamajig' does not exist: /dev/abc/:commons:thingamajig

另一个更新:所以我想出了如何排除那些实际上没有任何Java但无论如何都会被Java插件拾取的项目.这有帮助,但我还没有走出困境.我还添加了这个以尝试获取项目目录的真正价值:

Another update: So I've figured out how to exclude projects that don't actually have any Java in them but get picked up by the Java plugin anyway. This has helped but I'm not out of the woods yet. I've also added this in an attempt to get the real value of the project's directory:

subprojects {
    sonarqube {
        println "*************"
        println "$project.name"
        properties.each {
            println "$it.key, $it.value"
        }
        println "Project Dir: $projectDir"
        println "Project Dir: $project.projectDir"

        println "*************"
    }
}

稍后再详细介绍......好吧......这里是一些调试级别的东西:

More on this in a bit.... OK... here is some debug level stuff:

15:49:31.419 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':sonarqube'.
15:49:31.512 [INFO] [org.sonarqube.gradle.SonarQubeTask] User cache: /home/user/.sonar/cache
15:49:31.512 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Extract sonar-scanner-api-batch in temp...
15:49:31.512 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Get bootstrap index...
15:49:31.512 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Download: http://localhost:9000/batch_bootstrap/index
15:49:31.518 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Get bootstrap completed
15:49:31.519 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Create isolated classloader...
15:49:31.520 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Start temp cleaning...
15:49:31.521 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Temp cleaning done
15:49:31.521 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Execution getVersion
15:49:31.522 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Execution start
15:49:31.607 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Publish global mode
15:49:31.639 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] cache: /home/user/.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000/global
15:49:31.653 [INFO] [org.sonarqube.gradle.SonarQubeTask] Load global repositories
15:49:31.730 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] GET 200 http://localhost:9000/batch/global | time=75ms
15:49:31.761 [INFO] [org.sonarqube.gradle.SonarQubeTask] Load global repositories (done) | time=109ms
15:49:31.778 [INFO] [org.sonarqube.gradle.SonarQubeTask] User cache: /home/user/.sonar/cache
15:49:32.035 [INFO] [org.sonarqube.gradle.SonarQubeTask] Load plugins index
15:49:32.036 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] GET 200 http://localhost:9000/deploy/plugins/index.txt | time=1ms
15:49:32.037 [INFO] [org.sonarqube.gradle.SonarQubeTask] Load plugins index (done) | time=2ms
15:49:32.037 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Load plugins
15:49:32.041 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Load plugins (done) | time=4ms
15:49:32.048 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] API compatibility mode is enabled on plugin C# [csharp] (built with API lower than 5.2)
15:49:32.048 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] API compatibility mode is enabled on plugin Java [java] (built with API lower than 5.2)
15:49:32.048 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] API compatibility mode is enabled on plugin SVN [scmsvn] (built with API lower than 5.2)
15:49:32.048 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] API compatibility mode is enabled on plugin Git [scmgit] (built with API lower than 5.2)
15:49:32.048 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] API compatibility mode is enabled on plugin JavaScript [javascript] (built with API lower than 5.2)
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Plugins:
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask]   * C# 4.4 (csharp)
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask]   * Java 3.10 (java)
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask]   * SVN 1.2 (scmsvn)
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask]   * Git 1.0 (scmgit)
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask]   * JavaScript 2.10 (javascript)
15:49:32.099 [INFO] [org.sonarqube.gradle.SonarQubeTask] Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
15:49:32.099 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Work directory: /development/eas/build/sonar
15:49:32.099 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Execution getVersion
15:49:32.099 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Execution execute
15:49:32.237 [INFO] [org.sonarqube.gradle.SonarQubeTask] Process project properties
15:49:32.244 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':sonarqube'
15:49:32.244 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :sonarqube FAILED
15:49:32.244 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :sonarqube (Thread[Daemon worker Thread 22,5,main]) completed. Took 5.151 secs.
15:49:32.244 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[Daemon worker Thread 22,5,main]] finished, busy: 24.352 secs, idle: 0.053 secs
15:49:32.245 [ERROR] [org.gradle.BuildExceptionReporter] 
15:49:32.245 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
15:49:32.245 [ERROR] [org.gradle.BuildExceptionReporter] 
15:49:32.245 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
15:49:32.245 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':sonarqube'.

如果我没看错的话,这可能是一个缺失或不正确的属性.有没有更好的方法让我转储这些以便我检查它们?

Could be a missing or incorrect property if I'm reading this correctly. Is there a better way for me to dump these so I can check em?

好的,我也想通了:

gradle sonarqube -DsonarRunner.dumpToFile=out.properties

虽然那里没有什么明显的.我看到项目失败的地方,但为基目录设置的值似乎是正确的.

Nothing obvious in there though. I see where the project is failing but the value set for the base directory seems correct.

好的,这真的很奇怪.如果我运行上述内容,我会得到:

OK here is something really weird. If I run the above, I get:

BUILD SUCCESSFUL

...特别是因为据我所知它并不成功.

...especially since it was not successful as far as I can tell.

好的,我刚刚找到了这些,我已经更新了调试级别的东西:

OK I just found these and I've updated the debug level stuff:

property "sonar.verbose", "true"
property "sonar.log.level", "TRACE"

我仍然没有看到任何相关的内容.

I still don't see anything pertinent there though.

推荐答案

sonarqube {
    properties {
        property "sonar.exclusions", "src/AbstractData.java,src/preprocessor/*.java,src/Service.java"
               }
          }

对我有用,试试

这篇关于使用 gradle/sonar/Jacoco 排除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆