33

I have maven installed on my local machine and I'm trying to test out Sonar installed on a remote box.

I found a few post online to configure settings.xml (maven\config\settings.xml) and append a profile entry...which I did but does not work

<profile>
   <id>sonar</id>
   <activation>
      <activeByDefault>true</activeByDefault>
   </activation>
   <properties>
      <!-- SERVER ON A REMOTE HOST -->
      <sonar.host.url>http://remotebox:9000</sonar.host.url>
   </properties>
</profile>

What is the cli way? I tried several options but nothing worked.

I tried: mvn sonar:sonar http://remotebox:9000

What is the correct syntax?

Thanks in advance. Damian

PS. this works fine on the remote box where both maven and sonar are installed...i just want to try it my box to the remote box.

Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
Damian
  • 339
  • 1
  • 3
  • 4
  • I think only mvn sonar:sonar should be enough – suat Sep 22 '11 at 17:04
  • 1
    I don't have sonar installed on my local machine...its on a remote machine. mvn sonar:sonar yields '[INFO] Sonar server can not be reached. Please check the parameter 'sonar.host.url': http://localhost:9000' – Damian Sep 22 '11 at 17:10

5 Answers5

39

Running sonar with

mvn sonar:sonar -Dsonar.jdbc.url=jdbc:h2:tcp://ipaddr:9092/sonar -Dsonar.host.url=http://ipaddr:9000

,where ipaddr is your remote host, seems to work.

teknopaul
  • 6,505
  • 2
  • 30
  • 24
  • 1
    also changed the sonar server config to use actual host name instead of localhost – Raul May 29 '13 at 11:36
25

Up to Version 5.2 beside the sonar.host.url you also have to specify the database parameters as described here. That way it works for me.

Configuration example

<profile>
    <id>sonar</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
        <!-- EXAMPLE FOR MYSQL -->
        <sonar.jdbc.url>
          jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8
        </sonar.jdbc.url>
        <sonar.jdbc.username>sonar</sonar.jdbc.username>
        <sonar.jdbc.password>sonar</sonar.jdbc.password>

        <!-- optional URL to server. Default value is http://localhost:9000 -->
        <sonar.host.url>
          http://myserver:9000
        </sonar.host.url>
    </properties>
</profile>

Since Version 5.2 this not not necessary anymore:

Quote:

Scanners don't access the database

This is the biggest change of this new version: scanners (e.g. Sonar Runner) no longer access the database, they only use web services to communicate with the server. In practice, this means that the JDBC connection properties can now be removed from analysis CI jobs: sonar.jdbc.url, sonar.jdbc.username, sonar.jdbc.password

FrVaBe
  • 47,963
  • 16
  • 124
  • 157
  • 6
    Exact. The command-line is : mvn sonar:sonar -Dsonar.host.url=http://remotebox:9000 – Simon Brandhof Sep 24 '11 at 07:12
  • 1
    this example does not work for me. apparently the protocol needs to be specified as well: mvn sonar:sonar -Dsonar.host.url=http://remotebox:9000/ This does not solve the db connection to the default derby db though – Raul May 29 '13 at 11:26
  • @Raul Be aware of the fact that using the embedded derby/H2 database does not support remote connections (only localhost). Have a look at Mark O'Connor answer. – FrVaBe May 29 '13 at 12:08
  • the link has gone dead unfortunately – pvgoddijn Feb 25 '15 at 10:42
  • @pvgoddijn Thanks for letting me know. Link is fixed now. – FrVaBe Feb 25 '15 at 12:24
  • @FrVaBe You have to login to see the link – nyxz Jan 11 '16 at 13:38
  • 1
    @nyxz the original link does not exist anymore so I changed it to a different location. Beside that I added a note to the changes since version 5.2 - which make the configuration of the database paramteres obsolete. Thanks. – FrVaBe Jan 11 '16 at 14:53
14

Just the following works for sonar-maven-plugin:3.2:

mvn sonar:sonar -Dsonar.host.url=http://<sonarqubeserver>:<port>

Rocky Inde
  • 1,511
  • 1
  • 20
  • 27
7

Problem 1

As explained you need to specify the JDBC connection details, otherwise Sonar will attempt to talk to the embedded Derby instance, it assumes is running on localhost.

Problem 2

Are you using Derby? Well, the default configuration of Derby does not accept remote connections, but only connections from the same host.

The SONAR-1039 issue explains how to work-around this problem, but my advise would be to setup a full-blown database such as MySQL or Postgresql.

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
0

I had some problem and then realized, I was running mavn on parent pom whereas sonar configuration was in a child pom, for which I wanted analysis report anyway, so running mvn sonar:sonar with child pom worked.

Asit
  • 1