Sonar plugin does not work with sonar-checkstyle-plugin v2.4 #401

Closed
cypai opened this Issue Nov 11, 2015 · 13 comments

Projects

None yet

3 participants

@cypai
Contributor
cypai commented Nov 11, 2015

I get a guava dependency error during project analysis with the most recently released version of sonar-checkstyle-plugin (v2.4).

The same issue is mentioned here:
https://groups.google.com/d/msg/sonarqube/u9ZLuLc0ZXc/aPGhBA1LBwAJ

Related issue:
https://groups.google.com/d/msg/sonarqube/we1uaK570m8/QAukuq9Mij0J

The sonar-checkstyle-plugin developers were forced to shade guava into their jar because of compatibility issues between SonarQube's old version of guava and the main checkstyle project. Their suggested fix for sevntu is to shade guava into the sevntu-checkstyle-sonar-plugin jar like they did. I can confirm that shading the jars will fix both of the issues linked above.

Link to their shading pom: https://github.com/SonarCommunity/sonar-checkstyle/blob/4a01ebcbd1ba176f0975e04b31c3312b78ff2c43/checkstyle-all/pom.xml

Error stack trace here:
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project stuff: com.puppycrawl.tools.checkstyle.api.FileContents.getCComments()Lcom/google/common/collect/ImmutableMap; -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project stuff: com.puppycrawl.tools.checkstyle.api.FileContents.getCComments()Lcom/google/common/collect/ImmutableMap;
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: com.puppycrawl.tools.checkstyle.api.FileContents.getCComments()Lcom/google/common/collect/ImmutableMap;
at org.codehaus.mojo.sonar.bootstrap.ExceptionHandling.handle(ExceptionHandling.java:41)
at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:139)
at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:132)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: java.lang.NoSuchMethodError: com.puppycrawl.tools.checkstyle.api.FileContents.getCComments()Lcom/google/common/collect/ImmutableMap;
at com.github.sevntu.checkstyle.checks.coding.ForbidCCommentsInMethods.beginTree(ForbidCCommentsInMethods.java:55)
at com.puppycrawl.tools.checkstyle.TreeWalker.notifyBegin(TreeWalker.java:356)
at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:328)
at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:204)
at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:79)
at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:266)
at org.sonar.plugins.checkstyle.CheckstyleExecutor.execute(CheckstyleExecutor.java:87)
at org.sonar.plugins.checkstyle.CheckstyleSensor.analyse(CheckstyleSensor.java:57)
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:79)
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:70)
at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:119)
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:194)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:233)
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:228)
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:226)
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:221)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:64)
at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:51)
at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:125)
at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:173)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:135)
... 22 more

@Vladlis Vladlis was assigned by romani Nov 13, 2015
@romani
Member
romani commented Nov 14, 2015

from @cypai :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.2</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml
                </dependencyReducedPomLocation>
                <artifactSet>
                    <includes>
                        <include>*</include>
                    </includes>
                </artifactSet>
                <relocations>
                    <relocation>
                        <pattern>com.google.common</pattern>
                        <shadedPattern>com.puppycrawl.tools.checkstyle.guava
                        </shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
        </execution>
    </executions>
</plugin>
@cypai
Contributor
cypai commented Nov 16, 2015

Updated version to make a smaller jar

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.2</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml
                </dependencyReducedPomLocation>
                <artifactSet>
                    <includes>
                        <include>com.github.sevntu.checkstyle</include>
                    </includes>
                </artifactSet>
                <relocations>
                    <relocation>
                        <pattern>com.google.common</pattern>
                        <shadedPattern>com.puppycrawl.tools.checkstyle.guava
                        </shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
        </execution>
    </executions>
</plugin>
@Vladlis
Contributor
Vladlis commented Nov 17, 2015

@cypai, thanks a lot!

@Vladlis Vladlis added a commit to Vladlis/sevntu.checkstyle that referenced this issue Nov 17, 2015
@Vladlis Vladlis Issue #401: Shade Guava in sonar-plugin 99acfbc
@Vladlis Vladlis added a commit to Vladlis/sevntu.checkstyle that referenced this issue Nov 17, 2015
@Vladlis Vladlis Issue #401: Shade Guava in sonar-plugin 0a21d3a
@Vladlis
Contributor
Vladlis commented Dec 3, 2015

@cypai, please, tell me how exactly do you run sonar?
I try to run sonar server, but it fails with exception: https://gist.github.com/Vladlis/9c5fa8703ed19725513f
no matter what I try to use:
with shade plugin and without, on linux and windows, with java7 and java8, on Sonar 4.5.6 or Sonar 5.2

@cypai
Contributor
cypai commented Dec 3, 2015

@Vladlis
What are your sonar plugins? Make sure that the official checkstyle plugin is version 2.4, and the sonar Java plugin is at least 3.7.

@Vladlis
Contributor
Vladlis commented Dec 3, 2015

@cypai
They are - sonar-checkstyle-plugin-2.4 & sonar-java-plugin-3.7.1

@cypai
Contributor
cypai commented Dec 4, 2015

@Vladlis
Does sonar run if you remove the checkstyle and sevntu jars?

@Vladlis
Contributor
Vladlis commented Dec 4, 2015

@cypai
Yes, it runs without them and with any of them without the other one. (Of course we cannot use checkstyle with sevntu jar only)

@cypai
Contributor
cypai commented Dec 5, 2015

@Vladlis
Here's a copy of my pom.xml in sevntu-checkstyle-sonar-plugin: https://gist.github.com/cypai/a745d85285eafb3c90a5

@Vladlis
Contributor
Vladlis commented Dec 5, 2015

@cypai
The same error :(

@Vladlis
Contributor
Vladlis commented Dec 5, 2015

Well, looks like I did smth wrong while building jar. Everything's good with the jar @romani gave me.

@romani
Member
romani commented Dec 5, 2015

merged.

@romani romani closed this Dec 5, 2015
@romani romani added this to the 1.17.1 milestone Dec 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment