1
votes

I have been following this guide to configure Sonar for our project: http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Scanner+for+Gradle

This is a multi module project where we have a master project on the same level as the submodules, e.g:

master/build.gradle
sub1/build.gradle
sub2/build.gradle

Sonar is configured using mostly default properties:

subprojects {
  apply plugin: 'org.sonarqube'

  sonarqube {
    properties {
      property "sonar.host.url", "http://192.168.1.2:9000/"
    }
  }
  ...
}

So I try to skip one of the projects by adding this block (below subprojects):

project(":sub2") {
  sonarqube {
    skipProject = true
  }
}

But when executing "gradle sonarqube" from the master project I get this exception:

...
Caused by: java.lang.IllegalStateException: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources
at org.sonar.batch.scan.ProjectReactorBuilder.checkMandatoryProperties(ProjectReactorBuilder.java:331)
at org.sonar.batch.scan.ProjectReactorBuilder.defineRootProject(ProjectReactorBuilder.java:187)
at org.sonar.batch.scan.ProjectReactorBuilder.execute(ProjectReactorBuilder.java:132)
at org.sonar.batch.scan.MutableProjectReactorProvider.provide(MutableProjectReactorProvider.java:35)
at org.picocontainer.injectors.MethodInjector.invokeMethod(MethodInjector.java:129)
at org.picocontainer.injectors.MethodInjector.access$000(MethodInjector.java:39)
at org.picocontainer.injectors.MethodInjector$2.run(MethodInjector.java:113)
at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)
at org.sonar.core.platform.ComponentContainer.getComponentByType(ComponentContainer.java:230)
at org.sonar.batch.scan.ProjectScanContainer.doBeforeStart(ProjectScanContainer.java:118)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:98)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85)
at org.sonar.batch.bootstrap.GlobalContainer.executeAnalysis(GlobalContainer.java:153)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:110)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:76)
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
... 71 more

What am I doing wrong? All help appreciated.

1

1 Answers

0
votes

It seems to me, that you've applied the sonarqube configuration in the root project as:

subprojects {
  apply plugin: 'org.sonarqube'

  sonarqube {
    properties {
      property "sonar.host.url", "http://192.168.1.2:9000/"
    }
  }
  ...
}

But you are trying to run the task sonarqube from the root project, which is not configured, since you've done it just for subprojects. Try to run this task for the specified project, as gradle :sub1:sonarqube or create a custom task in the root project depending on the subprojects sonarqube tasks, which will run them all.