使用 gradle/sonar/Jacoco 排除项目

本文介绍了使用 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 排除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2

admin_action_{$_REQUEST[‘action’]}

do_action( "admin_action_{$_REQUEST[‘action’]}" )动作钩子::在发送“Action”请求变量时激发。Action Hook: Fires when an ‘action’ request variable is sent.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$_REQUEST['action']引用从GET或POST请求派生的操作。源码(Source)更新版本源码位置使用被使用2.6.0 wp-admin/admin.php:...

日期:2020-09-02 17:44:16 浏览:1159

admin_footer-{$GLOBALS[‘hook_suffix’]}

do_action( "admin_footer-{$GLOBALS[‘hook_suffix’]}", string $hook_suffix )操作挂钩:在默认页脚脚本之后打印脚本或数据。Action Hook: Print scripts or data after the default footer scripts.目录锚点:#说明#参数#源码说明(Description)钩子名的动态部分,$GLOBALS['hook_suffix']引用当前页的全局钩子后缀。参数(Parameters)参数类...

日期:2020-09-02 17:44:20 浏览:1060

customize_save_{$this->id_data[‘base’]}

do_action( "customize_save_{$this->id_data[‘base’]}", WP_Customize_Setting $this )动作钩子::在调用WP_Customize_Setting::save()方法时激发。Action Hook: Fires when the WP_Customize_Setting::save() method is called.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_data...

日期:2020-08-15 15:47:24 浏览:800

customize_value_{$this->id_data[‘base’]}

apply_filters( "customize_value_{$this->id_data[‘base’]}", mixed $default )过滤器::过滤未作为主题模式或选项处理的自定义设置值。Filter Hook: Filter a Customize setting value not handled as a theme_mod or option.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_date['base'],指的是设置...

日期:2020-08-15 15:47:24 浏览:887

get_comment_author_url

过滤钩子:过滤评论作者的URL。Filter Hook: Filters the comment author’s URL.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/comment-template.php:32610...

日期:2020-08-10 23:06:14 浏览:925

network_admin_edit_{$_GET[‘action’]}

do_action( "network_admin_edit_{$_GET[‘action’]}" )操作挂钩:启动请求的处理程序操作。Action Hook: Fires the requested handler action.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$u GET['action']引用请求的操作的名称。源码(Source)更新版本源码位置使用被使用3.1.0 wp-admin/network/edit.php:3600...

日期:2020-08-02 09:56:09 浏览:873

network_sites_updated_message_{$_GET[‘updated’]}

apply_filters( "network_sites_updated_message_{$_GET[‘updated’]}", string $msg )筛选器挂钩:在网络管理中筛选特定的非默认站点更新消息。Filter Hook: Filters a specific, non-default site-updated message in the Network admin.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分$_GET['updated']引用了非默认的...

日期:2020-08-02 09:56:03 浏览:855

pre_wp_is_site_initialized

过滤器::过滤在访问数据库之前是否初始化站点的检查。Filter Hook: Filters the check for whether a site is initialized before the database is accessed.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/ms-site.php:93910...

日期:2020-07-29 10:15:38 浏览:825

WordPress 的SEO 教学:如何在网站中加入关键字(Meta Keywords)与Meta 描述(Meta Description)?

你想在WordPress 中添加关键字和meta 描述吗?关键字和meta 描述使你能够提高网站的SEO。在本文中,我们将向你展示如何在WordPress 中正确添加关键字和meta 描述。为什么要在WordPress 中添加关键字和Meta 描述?关键字和说明让搜寻引擎更了解您的帖子和页面的内容。关键词是人们寻找您发布的内容时,可能会搜索的重要词语或片语。而Meta Description则是对你的页面和文章的简要描述。如果你想要了解更多关于中继标签的资讯,可以参考Google的说明。Meta 关键字和描...

日期:2020-10-03 21:18:25 浏览:1695

谷歌的SEO是什么

SEO (Search Engine Optimization)中文是搜寻引擎最佳化,意思近于「关键字自然排序」、「网站排名优化」。简言之,SEO是以搜索引擎(如Google、Bing)为曝光媒体的行销手法。例如搜寻「wordpress教学」,会看到本站的「WordPress教学:12个课程…」排行Google第一:关键字:wordpress教学、wordpress课程…若搜寻「网站架设」,则会看到另一个网页排名第1:关键字:网站架设、架站…以上两个网页,每月从搜寻引擎导入自然流量,达2万4千:每月「有机搜...

日期:2020-10-30 17:23:57 浏览:1298