How to scan with multiple ant compiles?

Hi,

I am very new to SonarQube, so my knowledge is very limited and this is my first post here, so please be gentle.

Our legacy product probably is using old technologies and we use ant to compile our java codes. The main build.xml is like this ( partial ) :

    <target name="exports_1" depends="setup">
        <!-- Build lowest level components needed by all projects. This builds serially. -->
        <echo message="Step 1: ServiceInterfaceEjb, AuthLdap"/>
        <ant antfile="${top}/Java/Infrastructure/Logging/build.xml" inheritall="false"/>
        <ant antfile="${top}/Java/DataModel/XmlBinding/build.xml" inheritall="false"/>
        <ant antfile="${top}/Java/DataModel/Entities/build.xml" inheritall="false"/>
        <ant antfile="${top}/Auth/AuthLdap/build.xml" inheritall="false"/>
        <ant antfile="${top}/Java/Infrastructure/Infrastructure/build.xml" inheritall="false"/>
        <ant antfile="${top}/Java/Infrastructure/Security/build.xml" inheritall="false"/>
        <ant antfile="${top}/Java/Enterprise/CacheManager/build.xml" inheritall="false"/>
        <ant antfile="${top}/Auth/src/build_ldap_gui_tool.xml" target="ldap_gui_dist" inheritall="false"/>
        <ant antfile="${top}/Auth/LdapAuth/build_ldap_auth.xml" inheritall="false"/>
        <ant antfile="${top}/Java/Test/TestLib/build.xml" inheritall="false"/>
    </target>

Currently, I can go to each directory, for example : ${top}/Java/Infrastructure/Logging , and run a “ant sonar” command to scan the java code under there

ant sonar -Dsonar.login=xxxxxxxxxxx -Dsonar.userHome=pwd/.sonar

if I run it on another directory, the scan result of the project will be wipe out with the new scan’s result.
And we have about 70 lines of these “ant antfile” commands in the build.xml , I am wondering if there is a way we could do the “ant sonar” scan in 1 command ?

Our company’s SonarQube verions is Enterprise Edition Version 8.9.1 (build 44547)
and the sonar ant scanner I download is sonarqube-ant-task-2.7.1.1951.jar

Any help or suggestion would be great.
Please let me know if I need to provide more information.

Thanks,
James

Hi James,

Welcome to the community!

It sounds like you’re passing the same project key for every (sub?)project. You’ll want to edit each build.xml to set a unique sonar.projectKey and that will fix the overwriting. Then, since you have Enterprise Edition($$) you can stitch the projects back together if you need to as either one or more Applications (pseudo-projects) or Portfolios

 
HTH,
Ann

Thank you Ann.
Looks like there is no easy way to perform the “ant sonar” in one command ( or put all the directories under some parameter ). Not sure if the admin of SQ in my company will allow me to have 70+ project keys. But I can try to look into what you mentioned about stitching/pseudo-projects/portfolios.

Cheers,
James

1 Like