Sonarqube 反 IllegalStateException;不获取属性文件
Sonarqube ant IllegalStateException; not picking up properties file
我正在测试 Sonarqube 5.3 和 Sonarqube Ant 2.4 jar,但是 运行在我的构建脚本中调用 ant sonar 目标时遇到了问题
这是我的构建脚本 (C:\dev\poc\sonarpoc\sonarpoc.xml):
<project name="sonarpoc" basedir="." default="init" xmlns:sonar="antlib:org.sonar.ant">
...
<target name="sonar">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonarqube-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="/dev/jars/opensource/sonarqube/2.4/sonarqube-ant-task-2.4.jar" />
</taskdef>
<!-- Execute the SonarQube analysis -->
<sonar:sonar />
</target>
....
<target name="build" depends="clean, compile, sonar, build-ear"/>
要从我调用的命令行执行:
C:\dev\poc\sonarpoc>ant -f sonarpoc.xml clean build
我在 C:\dev\poc\sonarpoc 中定义了一个声纳-project.properties,其中包含
# required metadata
sonar.host.url=http://localhost:9000
sonar.projectKey=dev:sonarpoc
sonar.projectName=DEV-sonarpoc
sonar.projectVersion=1.0
sonar.sources=source
到目前为止,还不错。我现在可以 运行 sonar-运行ner 并且可以在 http://localhost:9000.
看到分析结果
但是,当我 运行 上面的 ant 脚本时,我得到了这个:
compile:
sonar:
[sonar:sonar] Apache Ant version 1.7.1 compiled on June 27 2008
[sonar:sonar] SonarQube Ant Task version: 2.4
[sonar:sonar] Loaded from: file:/C:/dev/jars/opensource/sonarqube/2.4/sonarqube-ant-task-2.4.jar
[sonar:sonar] User cache: C:\Users\john\.sonar\cache
[sonar:sonar] Load global repositories
[sonar:sonar] Load global repositories (done) | time=144ms
[sonar:sonar] User cache: C:\Users\john\.sonar\cache
[sonar:sonar] Load plugins index
[sonar:sonar] Load plugins index (done) | time=13ms
[sonar:sonar] Default locale: "en_IE", source code encoding: "windows-1252" (analysis is platform dependent)
[sonar:sonar] Process project properties
BUILD FAILED
java.lang.IllegalStateException: Unable to load component class org.sonar.batch.scan.ProjectLock
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:62)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)
at org.sonar.core.platform.ComponentContainer.getComponentByType(ComponentContainer.java:262)
at org.sonar.batch.scan.ProjectScanContainer.doBeforeStart(ProjectScanContainer.java:109)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:130)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
at org.sonar.batch.task.ScanTask.execute(ScanTask.java:55)
at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:122)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119)
at org.sonar.runner.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.sonar.runner.impl.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:61)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:274)
at org.sonar.runner.api.EmbeddedRunner.runAnalysis(EmbeddedRunner.java:165)
at org.sonar.runner.api.EmbeddedRunner.runAnalysis(EmbeddedRunner.java:152)
at org.sonarsource.scanner.ant.SonarQubeTask.launchAnalysis(SonarQubeTask.java:72)
at org.sonarsource.scanner.ant.SonarQubeTask.execute(SonarQubeTask.java:55)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.api.batch.bootstrap.ProjectReactor
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getCompoent(ComponentContainer.java:62)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
at org.picocontainer.parameters.BasicComponentParameter.resolveInstance(BasicComponentParameter.java:118)
at org.picocontainer.parameters.ComponentParameter.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.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.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:60)
... 39 more
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:323)
at org.sonar.batch.scan.ProjectReactorBuilder.defineRootProject(ProjectReactorBuilder.java:179)
at org.sonar.batch.scan.ProjectReactorBuilder.execute(ProjectReactorBuilder.java:124)
at org.sonar.batch.scan.MutableProjectReactorProvider.provide(MutableProjectReactorProvider.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.picocontainer.injectors.MethodInjector.invokeMethod(MethodInjector.java:129)
at org.picocontainer.injectors.MethodInjector.access[=13=]0(MethodInjector.java:39)
at org.picocontainer.injectors.MethodInjector.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.decorateComponentInstanceCompositeInjector.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.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:60)
... 53 more
Total time: 5 seconds
C:\dev\poc\sonarpoc>
Caused by: java.lang.IllegalStateException: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources
上面一行是问题所在。貌似ant任务不能像sonar-运行ner那样识别当前目录下有sonar-project.properties文件。
我认为需要额外的路径配置来告诉 ant 任务在当前目录中查找 sonar-project.properties 文件并使用它,但我不知道那是什么是。
我尝试添加:
到 C:\dev\poc\sonarpoc\sonarpoc.xml 但没有快乐。
编辑:
当我在命令行上指定声纳属性时,具有构建目标 运行 的 ant 脚本成功,即
C:\dev\poc\sonarpoc>ant -f sonarpoc.xml -Dsonar.projectKey=dev:sonarpoc -Dsonar.projectName=DEV-sonarpoc -Dsonar.projectVersion=1.0 -Dsonar.sources=source clean build
这强化了我的想法,即需要一些额外的路径配置来让 ant 目标获取属性文件。
有人遇到过这个吗?
SonarQube Scanner for Ant 不支持开箱即用的 "sonar-project.properties" 文件。如果您看一下 documentation page,您会发现必须在 Ant 文件中提供这些属性:
<!-- Define the SonarQube project properties -->
<property name="sonar.projectKey" value="org.codehaus.sonar:example-java-ant" />
<property name="sonar.projectName" value="Simple Java Project analyzed with the SonarQube Ant Task" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.java.binaries" value="build" />
<property name="sonar.java.libraries" value="lib/*.jar" />
如果您仍想使用属性文件来存放这些设置,我想您可以为此目的调用 LoadProperties Ant task。但是我从来没有尝试过这个所以我不能保证这个有效。
解决方法很简单,请确认您指向的目录是否正确
有时在cmd中指向C:\
要移动到另一个目录,您需要添加 D:
所以总是在cmd中验证,如果你指向正确目录的目录。
在 SonarQube 5.1.2 上,我可以使用参数 -propertyfile sonar-project.properties
.
设置 属性 文件进行蚂蚁分析
我正在测试 Sonarqube 5.3 和 Sonarqube Ant 2.4 jar,但是 运行在我的构建脚本中调用 ant sonar 目标时遇到了问题
这是我的构建脚本 (C:\dev\poc\sonarpoc\sonarpoc.xml):
<project name="sonarpoc" basedir="." default="init" xmlns:sonar="antlib:org.sonar.ant">
...
<target name="sonar">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonarqube-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="/dev/jars/opensource/sonarqube/2.4/sonarqube-ant-task-2.4.jar" />
</taskdef>
<!-- Execute the SonarQube analysis -->
<sonar:sonar />
</target>
....
<target name="build" depends="clean, compile, sonar, build-ear"/>
要从我调用的命令行执行:
C:\dev\poc\sonarpoc>ant -f sonarpoc.xml clean build
我在 C:\dev\poc\sonarpoc 中定义了一个声纳-project.properties,其中包含
# required metadata
sonar.host.url=http://localhost:9000
sonar.projectKey=dev:sonarpoc
sonar.projectName=DEV-sonarpoc
sonar.projectVersion=1.0
sonar.sources=source
到目前为止,还不错。我现在可以 运行 sonar-运行ner 并且可以在 http://localhost:9000.
看到分析结果但是,当我 运行 上面的 ant 脚本时,我得到了这个:
compile:
sonar:
[sonar:sonar] Apache Ant version 1.7.1 compiled on June 27 2008
[sonar:sonar] SonarQube Ant Task version: 2.4
[sonar:sonar] Loaded from: file:/C:/dev/jars/opensource/sonarqube/2.4/sonarqube-ant-task-2.4.jar
[sonar:sonar] User cache: C:\Users\john\.sonar\cache
[sonar:sonar] Load global repositories
[sonar:sonar] Load global repositories (done) | time=144ms
[sonar:sonar] User cache: C:\Users\john\.sonar\cache
[sonar:sonar] Load plugins index
[sonar:sonar] Load plugins index (done) | time=13ms
[sonar:sonar] Default locale: "en_IE", source code encoding: "windows-1252" (analysis is platform dependent)
[sonar:sonar] Process project properties
BUILD FAILED
java.lang.IllegalStateException: Unable to load component class org.sonar.batch.scan.ProjectLock
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:62)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)
at org.sonar.core.platform.ComponentContainer.getComponentByType(ComponentContainer.java:262)
at org.sonar.batch.scan.ProjectScanContainer.doBeforeStart(ProjectScanContainer.java:109)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:130)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
at org.sonar.batch.task.ScanTask.execute(ScanTask.java:55)
at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:122)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119)
at org.sonar.runner.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.sonar.runner.impl.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:61)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:274)
at org.sonar.runner.api.EmbeddedRunner.runAnalysis(EmbeddedRunner.java:165)
at org.sonar.runner.api.EmbeddedRunner.runAnalysis(EmbeddedRunner.java:152)
at org.sonarsource.scanner.ant.SonarQubeTask.launchAnalysis(SonarQubeTask.java:72)
at org.sonarsource.scanner.ant.SonarQubeTask.execute(SonarQubeTask.java:55)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.api.batch.bootstrap.ProjectReactor
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getCompoent(ComponentContainer.java:62)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
at org.picocontainer.parameters.BasicComponentParameter.resolveInstance(BasicComponentParameter.java:118)
at org.picocontainer.parameters.ComponentParameter.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.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.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:60)
... 39 more
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:323)
at org.sonar.batch.scan.ProjectReactorBuilder.defineRootProject(ProjectReactorBuilder.java:179)
at org.sonar.batch.scan.ProjectReactorBuilder.execute(ProjectReactorBuilder.java:124)
at org.sonar.batch.scan.MutableProjectReactorProvider.provide(MutableProjectReactorProvider.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.picocontainer.injectors.MethodInjector.invokeMethod(MethodInjector.java:129)
at org.picocontainer.injectors.MethodInjector.access[=13=]0(MethodInjector.java:39)
at org.picocontainer.injectors.MethodInjector.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.decorateComponentInstanceCompositeInjector.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.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:60)
... 53 more
Total time: 5 seconds
C:\dev\poc\sonarpoc>
Caused by: java.lang.IllegalStateException: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources
上面一行是问题所在。貌似ant任务不能像sonar-运行ner那样识别当前目录下有sonar-project.properties文件。
我认为需要额外的路径配置来告诉 ant 任务在当前目录中查找 sonar-project.properties 文件并使用它,但我不知道那是什么是。
我尝试添加: 到 C:\dev\poc\sonarpoc\sonarpoc.xml 但没有快乐。
编辑: 当我在命令行上指定声纳属性时,具有构建目标 运行 的 ant 脚本成功,即
C:\dev\poc\sonarpoc>ant -f sonarpoc.xml -Dsonar.projectKey=dev:sonarpoc -Dsonar.projectName=DEV-sonarpoc -Dsonar.projectVersion=1.0 -Dsonar.sources=source clean build
这强化了我的想法,即需要一些额外的路径配置来让 ant 目标获取属性文件。
有人遇到过这个吗?
SonarQube Scanner for Ant 不支持开箱即用的 "sonar-project.properties" 文件。如果您看一下 documentation page,您会发现必须在 Ant 文件中提供这些属性:
<!-- Define the SonarQube project properties -->
<property name="sonar.projectKey" value="org.codehaus.sonar:example-java-ant" />
<property name="sonar.projectName" value="Simple Java Project analyzed with the SonarQube Ant Task" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.java.binaries" value="build" />
<property name="sonar.java.libraries" value="lib/*.jar" />
如果您仍想使用属性文件来存放这些设置,我想您可以为此目的调用 LoadProperties Ant task。但是我从来没有尝试过这个所以我不能保证这个有效。
解决方法很简单,请确认您指向的目录是否正确
有时在cmd中指向C:\
要移动到另一个目录,您需要添加 D:
所以总是在cmd中验证,如果你指向正确目录的目录。
在 SonarQube 5.1.2 上,我可以使用参数 -propertyfile sonar-project.properties
.