我正在测试Sonarqube 5.3和Sonarqube Ant 2.4 jar但在我的构建脚本中调用ant声纳目标时遇到了问题
这是我的构建脚本(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中定义的sonar-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
到目前为止,这么好。我现在可以运行声纳 - 跑步者,可以在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$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.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$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.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-project.properties文件,如sonar-runner can。
我认为需要额外的路径配置来告诉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
这样可以强化我的想法,即需要一些额外的路径配置来获取蚂蚁目标以获取属性文件。
以前有人遇到过这个吗?
答案 0 :(得分:1)
Son的SonarQube扫描程序不支持开箱即用的“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。但我从来没有尝试过,所以我无法保证这一点。
答案 1 :(得分:0)
在SonarQube 5.1.2上我可以使用参数-propertyfile sonar-project.properties
设置蚂蚁分析的属性文件。
答案 2 :(得分:-1)
解决方案很简单,请确认您指向正确的目录
在cmd中,它指向C:\
要移至另一个目录,您需要添加D:
因此,如果您指向正确目录的目录,请始终在cmd中进行验证。