Mandatory properties missing when migrating to new

2019-09-03 14:27发布

问题:

I have a multi module project (with many sub-modules) defined in Sonar and it was working great until i've upgraded sonar to the newer version.

My previous settings were:

  1. a single parent build.xml that contain all of the general project properties like jdbc connection etc. Also it contained the <sonar:sonar /> task to run Sonar. This parent project does not contain any source / binaries, just the instruction to build the sub-modules.
  2. many sub-modules build.xml files that contained only the sub-module specific properties like sonar.projectKey, sonar.sources and sonar.binaries

Now in the new Sonar ant task I need to define everything in the parent buid.xml. I have defined it in the following way (I only show one sub-module here, I assume it should work the same if I add more modules later) :

<target name="sonar">
  <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
    <classpath path="build-utils/lib/sonar-ant-task-2.0.jar" />
  </taskdef>
  <!-- list of Sonar database related properties -->
  <property name="sonar.jdbc.url" value="jdbc:oracle:thin:@localhost/DB11g" />
  <property name="sonar.jdbc.driverClassName" value="oracle.jdbc.driver.OracleDriver" />
  <!-- for security reasons, pass these parameters from outside -->
  <property name="sonar.jdbc.username" value="" />
  <property name="sonar.jdbc.password" value="" />
  <property name="sonar.host.url" value="http://localhost:9000" />
  <!-- list of Sonar project related properties -->
  <property name="sonar.projectName" value="My Project" />
  <property name="sonar.projectKey" value="com.my.project" />
  <property name="sonar.projectVersion" value="7.3" />
  <property name="sonar.language" value="java" />
  <property name="sonar.libraries" value="server/third-party-jars"/>

  <property name="sonar.modules" value="admin-api" />
  <!-- all of the sub-modules -->
  <property name="admin-api.sonar.projectName" value="admin-api" />
  <property name="admin-api.sonar.projectBaseDir" location="server/admin/admin-api"/>
  <property name="admin-api.sonar.sources" value="src" />
  <property name="admin-api.sonar.binaries" value="build" />
  <sonar:sonar xmlns:sonar="antlib:org.sonar.ant" />
</target>

When I run the target I get the following error:

You must define the following mandatory properties for 'com.orca.rightv': sonar.sources

Another question, is there any way to keep the specific definition of the sub-modules in each module's build.xml like I did in the previous version ? That would save me a lot of work.

Thanks

回答1:

There's a bug in the current version of the Ant Task, which is related to the version of the Sonar Runner API embedded. This will be fixed in the next version: http://jira.codehaus.org/browse/SONARPLUGINS-2818

Meanwhile, you can define "sonar.sources" at the top, its value will be inherited in to modules (and obviously you can still override it in modules).

As for the definition of properties at module level, you can define those properties in a "sonar-project.properties" file that you put at the root of the module, like:

sonar.projectName=My Project
# following needed only to override the values defined in top build.xml
sonar.sources=src
sonar.binaries=build

, and just leave "admin-api.sonar.projectBaseDir" property (like you did) in the top build.xml file.



标签: sonarqube