Project exclude with gradle / sonar / Jacoco
<p>So we have a build with 90+ sub-projects where it's often the case that the directory doesn't perfectly match the project name. In some cases we have empty project-less parent directories and in others the name just doesn't match the directory structure. For example, the sub-directory for project <code>abc-toaster</code> might be named just <code>toaster</code>. The error is:</p>

<p>The base directory of the module '<code>:commons:thingamajig</code>' does not exist:<code>/dev/abc/:commons:thingamajig</code></p>

<p>...except there is no <code>build.gradle</code> in <code>commons/thingamajig</code> 
How can I get Sonar around this?  I've tried:</p>

<ol>
<li>Putting an empty dummy <code>build.gradle</code> in <code>commons/thingamajig</code> - No dice. Same error.</li>
<li>Setting <code>someModule.sonar.projectBaseDir</code> as mentioned here: <a href="https://stackoverflow.com/questions/21934591/sonar-properties-files">Sonar properties files</a></li>
<li>Running a full debug trace to see what pops up. Result: Nothing obvious.</li>
</ol>

<p>Where am I hosing this up?</p>

<p>Example Update:</p>

<pre><code>allprojects {
    sonarqube {
        file("$buildDir/classes").mkdirs();
        properties {
            property "sonar.exclusions", ["**/generated-src/**"]
            property "sonar.projectName", "ABC"
            property "sonar.projectKey", "$project.group:$project.name"
            property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
            property "sonar.projectBaseDir", "${project.rootDir}"
        }
    }
}
</code></pre>

<p>The above gives: </p>

<pre><code>Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.batch.scan.ProjectLock
...
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.api.batch.bootstrap.ProjectReactor
...
Caused by: java.lang.IllegalStateException: The base directory of the module ':commons:thingamajig' does not exist: /dev/abc/:commons:thingamajig
</code></pre>

<p>Another update:
So I've figured out how to exclude projects that don't actually have any Java in them but get picked up by the Java plugin anyway. This has helped but I'm not out of the woods yet. I've also added this in an attempt to get the real value of the project's directory:</p>

<pre><code>subprojects {
    sonarqube {
        println "*************"
        println "$project.name"
        properties.each {
            println "$it.key, $it.value"
        }
        println "Project Dir: $projectDir"
        println "Project Dir: $project.projectDir"

        println "*************"
    }
}
</code></pre>

<p>More on this in a bit.... OK... here is some debug level stuff:</p>

<pre><code>15:49:31.419 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':sonarqube'.
15:49:31.512 [INFO] [org.sonarqube.gradle.SonarQubeTask] User cache: /home/user/.sonar/cache
15:49:31.512 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Extract sonar-scanner-api-batch in temp...
15:49:31.512 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Get bootstrap index...
15:49:31.512 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Download: http://localhost:9000/batch_bootstrap/index
15:49:31.518 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Get bootstrap completed
15:49:31.519 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Create isolated classloader...
15:49:31.520 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Start temp cleaning...
15:49:31.521 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Temp cleaning done
15:49:31.521 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Execution getVersion
15:49:31.522 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Execution start
15:49:31.607 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Publish global mode
15:49:31.639 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] cache: /home/user/.sonar/ws_cache/http%3A%2F%2Flocalhost%3A9000/global
15:49:31.653 [INFO] [org.sonarqube.gradle.SonarQubeTask] Load global repositories
15:49:31.730 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] GET 200 http://localhost:9000/batch/global | time=75ms
15:49:31.761 [INFO] [org.sonarqube.gradle.SonarQubeTask] Load global repositories (done) | time=109ms
15:49:31.778 [INFO] [org.sonarqube.gradle.SonarQubeTask] User cache: /home/user/.sonar/cache
15:49:32.035 [INFO] [org.sonarqube.gradle.SonarQubeTask] Load plugins index
15:49:32.036 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] GET 200 http://localhost:9000/deploy/plugins/index.txt | time=1ms
15:49:32.037 [INFO] [org.sonarqube.gradle.SonarQubeTask] Load plugins index (done) | time=2ms
15:49:32.037 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Load plugins
15:49:32.041 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Load plugins (done) | time=4ms
15:49:32.048 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] API compatibility mode is enabled on plugin C# [csharp] (built with API lower than 5.2)
15:49:32.048 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] API compatibility mode is enabled on plugin Java [java] (built with API lower than 5.2)
15:49:32.048 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] API compatibility mode is enabled on plugin SVN [scmsvn] (built with API lower than 5.2)
15:49:32.048 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] API compatibility mode is enabled on plugin Git [scmgit] (built with API lower than 5.2)
15:49:32.048 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] API compatibility mode is enabled on plugin JavaScript [javascript] (built with API lower than 5.2)
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Plugins:
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask]   * C# 4.4 (csharp)
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask]   * Java 3.10 (java)
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask]   * SVN 1.2 (scmsvn)
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask]   * Git 1.0 (scmgit)
15:49:32.092 [DEBUG] [org.sonarqube.gradle.SonarQubeTask]   * JavaScript 2.10 (javascript)
15:49:32.099 [INFO] [org.sonarqube.gradle.SonarQubeTask] Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
15:49:32.099 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Work directory: /development/eas/build/sonar
15:49:32.099 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Execution getVersion
15:49:32.099 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Execution execute
15:49:32.237 [INFO] [org.sonarqube.gradle.SonarQubeTask] Process project properties
15:49:32.244 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':sonarqube'
15:49:32.244 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :sonarqube FAILED
15:49:32.244 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :sonarqube (Thread[Daemon worker Thread 22,5,main]) completed. Took 5.151 secs.
15:49:32.244 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[Daemon worker Thread 22,5,main]] finished, busy: 24.352 secs, idle: 0.053 secs
15:49:32.245 [ERROR] [org.gradle.BuildExceptionReporter] 
15:49:32.245 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
15:49:32.245 [ERROR] [org.gradle.BuildExceptionReporter] 
15:49:32.245 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
15:49:32.245 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':sonarqube'.
</code></pre>

<p>Could be a missing or incorrect property if I'm reading this correctly. Is there a better way for me to dump these so I can check em?</p>

<p>OK, figured that out too:</p>

<pre><code>gradle sonarqube -DsonarRunner.dumpToFile=out.properties
</code></pre>

<p>Nothing obvious in there though. I see where the project is failing but the value set for the base directory seems correct.</p>

<p>OK here is something really weird. If I run the above, I get:</p>

<pre><code>BUILD SUCCESSFUL
</code></pre>

<p>...especially since it was not successful as far as I can tell.</p>

<p>OK I just found these and I've updated the debug level stuff:</p>

<pre><code>property "sonar.verbose", "true"
property "sonar.log.level", "TRACE"
</code></pre>

<p>I still don't see anything pertinent there though. </p>