Running Sonar from ant for subprojects

75 views Asked by At

I am trying to integrate Sonar into my ant build script. I am able to make it work if I edit the build file of respective child projects by adding

<!-- Define the SonarQube project properties. removing the rest of properties for representing the problem-->
<property name="sonar.sources" value="src" />    
<!-- Define SonarScanner for Ant Target -->
    <target name="sonar"  xmlns:sonar="antlib:org.sonar.ant">
        <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
            <!-- Update the following line, or put the "sonarqube-ant-task-*.jar" file in your "$HOME/.ant/lib" folder 
            <classpath path="path/to/sonar/ant/task/lib/sonarqube-ant-task-*.jar" />-->
        </taskdef>
     
        <!-- Execute SonarScanner for Ant Analysis -->
        <sonar:sonar />
    </target>

as defined in https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-ant/

Now I want to move this config a level up from the sub project level to the root level so that I need to edit just one build file.

I was not able to move the above block as such since root project does not have a src folder and ant complained about that. So I tried to have a subant task for this

<subant target ="sonar"  xmlns:sonar="antlib:org.sonar.ant">
            <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
                <!-- Update the following line, or put the "sonarqube-ant-task-*.jar" file in your "$HOME/.ant/lib" folder 
                <classpath path="path/to/sonar/ant/task/lib/sonarqube-ant-task-*.jar" />-->
            </taskdef>
         
            <!-- Execute SonarScanner for Ant Analysis -->
            <sonar:sonar />
        </subant>

But for this I get the following error:

subant doesn't support the nested "taskdef" element.

Is there any workaround for this?

0

There are 0 answers