Sonar Scanner inspect multi module java project (Mixed eclipse with maven style) from command line

Well, recently I was need to review legacy project to do meassuring the code quality java.

There are a project with multi module structure based on old eclipse syle mixed with maven structure, I have 3 modules (2 in eclipse and 1 in maven) all of them are used to build the final artifact and I needed to do code inspection with sonarqube.

For example:


Fortunly sonar can manage this, let’s gets started.


  • A sonarqube instance (version 6.6)
  • Sonar scanner tool (version 3.0.3)
  • Compiled classes for projects to analize


  1. Login into sonar instance and select your profile (at the top rigth corner) then click on My profile
  2. Create a new token on tab Security, write a name for the token and click on Generate and copy the token string, becareful but you won’t be able to see this string again.
  3. Conigure your sonar scanner, open the instalation folder (where you uncompress it) and edit the file conf/, add the host and login token string:
    #Configure here general information about the environment, such as SonarQube DB details for example
    #No information about specific project should appear here
    #----- Default SonarQube server
    #----- Default source code encoding
    #----- Security (when 'sonar.forceAuthentication' is set to 'true')
  4. Create a project configuration file into your source code folder, go to project folder and create a file named, set the properties to binaries (compiled classes) and the source code per module, previously you need it compile the project with their modules. I use eclipse to build each of them. The content of file is something like these:
    #Required project data fron sonar
    #Lib Dir (Opcional) ej: path/library.jar,path/to/classes/dir
    # Project Language ( by default is Java)
    # Properties can obviously be overriden for
    # each module - just prefix them with the module ID
  5. Start the inspection, open an terminal and go to your root project folder and execute sonnar-scanner, this will start the code inspection (maybe take a long time, depend of  size of their projects) at the end you must see in the log something like this “ANALYSIS SUCCESSFUL, you can browse http://loaclhost:9000/dashboard/index/
  6. In the dashboard, on the code cactegory, you can see the result for the three modules.
    2018-01-25 19_06_14-Code - eph-tarjeta-palacio

That’s it.


Code inspection with Sonar Qube and sonar-runner

El análisis de código es fundamental para control de calidad en los desarrollos y para ello un producto muy bueno es el Sonar Qube .

Lo he utilizado para proyectos Java con maven,  pero veo hay una herramienta llamada sonar runner que te permite hacer el análisis sin necesidad de maven. Puedes utilizar esta herramienta para ejecutar la inspección de código de todos los lenguajes que soporte sonar.


Descargar Sonar Qube y Sonar Qube Runner, descomprimes ambos en una carpeta: Agregas la variable de entorno SONARQUBE_RUNNER_HOME y como valor escribes la ruta donde tienes la carpeta del Sonar Runner. Configurar Sonar Runner, editas el archivo SONARQUBE_RUNNER_HOME/conf/ agregas las siguientes líneas:

#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here

#----- Default SonarQube server

#----- Apache H2

#----- Global database settings

#----- Default source code encoding

Nota: Debes colocar los mismos datos  que tienes en tu archivo SONAR_SERVER_HOME/conf/, si utilzas otra base como Oracle o MySQL deben conicidir los datos de conexión. Seguir leyendo