sonar-maven-plugin:在多模块项目中扩展sonar.sources [英] sonar-maven-plugin: extending sonar.sources in multi-module project

查看:695
本文介绍了sonar-maven-plugin:在多模块项目中扩展sonar.sources的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用src/main/resources扩展默认为pom.xml,src/main/javasonar.sources,以便检查其中的XML文件.

I want to extend sonar.sources, which by default is pom.xml,src/main/java, by src/main/resources in order to check XML files that are located there.

由于我有一个多模块的maven项目(> 100个模块,嵌套),其中很多没有一个src/main/resources文件夹,而且大多数甚至没有src文件夹(例如,对于Packaging = pom).如果将sonar.sources设置为pom.xml,src/main/java,src/main/resourcespom.xml,src/main,则会导致生成错误:

This seemingly simple task turned out to be difficult since I have a multi-module maven project (> 100 modules, nested) with a lot of them don't have a src/main/resources folder and most of them not even a src folder (e.g. for packaging=pom). This leads to a build error if I set sonar.sources to pom.xml,src/main/java,src/main/resources or pom.xml,src/main:

[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.5:sonar (default-cli) on project xyz-parent: The directory 'C:\...\submodule\src\main\resources' does not exist for Maven module ... Please check the property sonar.sources -> [Help 1]

Sonar-Maven插件本身使用${project.build.sourceDirectory}在每个模块中进行操作.

The sonar-maven-plugin itself uses ${project.build.sourceDirectory} to do it right in every module.

我试图通过以下方式使用正则表达式将sonar.sources设置为src/main,方法是将/java(或Windows中的\java)切断

I tried to use regular expressions to set sonar.sources to src/main by cutting off /java (or \java on Windows) via

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.7</version>
  <executions>
    <execution>
      <id>regex-property</id>
      <goals>
        <goal>regex-property</goal>
      </goals>
      <configuration>
        <name>sonar.sources</name>
        <value>${project.build.sourceDirectory}</value>
        <regex>[/\\]+java$</regex>
        <replacement></replacement>
        <failIfNoMatch>false</failIfNoMatch>
      </configuration>
    </execution>
  </executions>
</plugin>

但这没有任何作用,我也不知道应该将其绑定到哪个生命周期阶段才能执行它.

But this does nothing and I have no idea to which lifecycle phase I should bind it to have it executed.

还是有一种方法可以避免由于sonar.sources中缺少目录而导致的错误?根据pom打包,而对于没有资源的earjar模块没有,则仅忽略当前声纳Maven源丢失的目录.

Or is there a way to avoid the error due to missing directory in sonar.sources? According to current sonar-maven source missing directories are only ignored if the POM has pom packaging but not for ear or jar modules without resources.

还是应该确保在声纳启动之前存在src/main?我可以为此使用什么钩子?

Or should I ensure src/main exists before sonar start? What hook may I use for that?

推荐答案

您可以执行的操作之一:

One of the things you can do it:

  • 在您的根POM中,定义以下属性:
    • sonar.sources.
    • sonar.inclusionssrc/main/**
    • =>这将包括SQ在src/main文件夹中的模块中找到的所有已知文件(如果存在)
    • In your root POM, define the following properties:
      • sonar.sources to be .
      • sonar.inclusions to be src/main/**
      • => this will include all the known files that SQ finds in your modules in the src/main folder if it exists

      这篇关于sonar-maven-plugin:在多模块项目中扩展sonar.sources的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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