Flex + ( Ant | Maven ) + Sonar

The title may sound like there are two possible ways how you can have your source code analyzed and published to sonar, but you better do not rejoice prematurely. After spending couple of hours trying to figure out how to make it work using ant I may have hit some nice articles, however sonar-ant-task seems to have major issues with sonar version 2.8. The solution is maven!

First of all, for “flex language” sonar uses FlexPMD. Sonar plugin/task should be able to take your source code and evaluate based on FlexPMD dependency. Unfortunately this thing is never done for you in case of sonar-ant-task. Even there is a simple way described you can invoke FlexPMD from Ant (you have to do slight changes for latest FlexPMD version), there is no way sonar 2.8 let you pass these results into its database. Ant way was a no-go for me.

Later I realized we already have some flex projects on sonar, but these get there using maven, while whole projects has been built by maven (flex-mojos). And as Sonar was initialy developed for maven, it is integrated really nicely. Even my current project is not being built by maven, there is a way to use minimal configuration just for sonar. It appeared there are already some maven – sonar config examples, all I needed to do in addition to this was adding pluginManagement, while we are not using latest maven version:

<build>
	<sourceDirectory>...</sourceDirectory>
	<pluginManagement>
		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>sonar-maven-plugin</artifactId>
				<version>1.0-beta-2</version>
			</plugin>
		</plugins>
	</pluginManagement>
</build>

Finally, the day was saved thanks to maven. So my preference to use maven or ant is 50:50 because, even if ant seems much easier to use, there are some thing that you just can not do for now.

Where to go from here:

Leave a comment

Please be polite and on topic. Your e-mail will never be published.