title: How to set sonar.projectBaseDir in SonarQube Scanner for Jenkins?
body: <p>I try to analyze one module of a multi module project in Jenkins with <a href="https://plugins.jenkins.io/sonar" rel="nofollow noreferrer">SonarQube Scanner</a> plug-in (version 2.5). Unfortunately, Jenkins picks the wrong module as working directory. </p>
  
  <p>In this particular case, I could change the order of the modules, but in general (more than one analyzed module) it is not working. So I want to fix the problem with the property <code>sonar.projectBaseDir</code>, see <a href="https://docs.sonarqube.org/display/SCAN/Advanced+SonarQube+Scanner+Usages" rel="nofollow noreferrer">Advanced SonarQube Scanner Usages</a>:</p>
  
  <blockquote>
    <h2>Alternate Analysis Directory</h2>
    
    <p>If the files to be analyzed are not in the directory where the analysis starts from, use the <code>sonar.projectBaseDir</code> property to move analysis to a different directory. E.G. analysis begins from <code>jenkins/jobs/myjob/workspace</code> but the files to be analyzed are in <code>ftpdrop/cobol/project1</code>.</p>
    
    <p><strong>sonar-project.properties</strong></p>
    
    <p>sonar.projectBaseDir=/home/ftpdrop/cobol/project1<br>
    sonar.sources=src<br>
    sonar.cobol.copy.directories=/copy  </p>
  </blockquote>
  
  <p>I tried following ways to set the <code>sonar.projectBaseDir</code> property to right module (<code>module2</code> instead of <code>module1</code>):</p>
  
  <ol>
  <li><p><code>sonar.projectBaseDir</code> in <code>sonar-project.properties</code> file</p>
  
  <p>But it doesn't work. The property in <code>sonar-project.properties</code> file is ignored. The log shows that the property is overriden with JVM option:</p>
  
  <p></p>
  
  <pre><code>/Users/test/jenkinsslave/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/bin/sonar-scanner -X -e -Dsonar.host.url=http://sonarqube:9090 -Dproject.settings=/Users/test/jenkinsslave/workspace/Test/module2/sonar-project.properties -Dsonar.projectBaseDir=/Users/test/jenkinsslave/workspace/Test/module1
  </code></pre>
  
  <p>I think that is a bug in  SonarQube Scanner plug-in, because <code>project.settings</code> is incompatible with  <code>sonar.projectBaseDir</code>, see <a href="https://docs.sonarqube.org/display/SCAN/Advanced+SonarQube+Scanner+Usages" rel="nofollow noreferrer">Advanced SonarQube Scanner Usages</a>:</p>
  
  <blockquote>
    <p>The property <code>project.settings</code> can be used to specify the path to the project configuration file (this option is incompatible with the <code>project.home</code> and <code>sonar.projectBaseDir</code> properties).</p>
  </blockquote></li>
  <li><p><code>sonar.projectBaseDir</code> as <em>JVM Options</em></p>
  
  <p>But it doesn't work. The property is ignored. The log shows that the property is overriden:</p>
  
  <p></p>
  
  <pre><code>/Users/test/jenkinsslave/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/bin/sonar-scanner -X -e -Dsonar.host.url=http://sonarqube:9090 -Dsonar.projectBaseDir=/Users/test/jenkinsslave/workspace/Test/module1
  </code></pre></li>
  <li><p><code>sonar.projectBaseDir</code> as <em>Additional arguments</em></p>
  
  <p>But it doesn't work. The log shows that the property is configured twice: </p>
  
  <p></p>
  
  <pre><code>/Users/test/jenkinsslave/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube_Scanner_2.8/bin/sonar-scanner -Dsonar.projectBaseDir=/Users/test/jenkinsslave/workspace/Test/module2 -X -e -Dsonar.host.url=http://sonarqube:9090 -Dsonar.projectBaseDir=/Users/test/jenkinsslave/workspace/Test/module1
  </code></pre>
  
  <p>I think that is a bug in SonarQube Scanner plug-in, because it should not add <code>sonar.projectBaseDir</code> option if there is already such option.</p></li>
  </ol>