简体   繁体   English

如何使用maven编译时获得Eclipse警告?

[英]How to get Eclipse Warnings when compiling with maven?

I have a Java project using m2eclipse. 我有一个使用m2eclipse的Java项目。 In my Eclipse, I get several Warnings. 在我的Eclipse中,我收到了几个警告。

How can I display those warnings in my maven compilation? 如何在我的maven编辑中显示这些警告? I want to use warnings-plugin on jenkins to keep track of the number of warnings. 我想在jenkins上使用warnings-plugin来跟踪警告的数量。

I found this post on how to enable warnings in maven, but it only gives me a small subset of warnings. 我发现这篇关于如何在maven中启用警告的帖子,但它只给了我一小部分警告。

Eg 例如

"The value of ... is not used" warnings don't show up. “没有使用......的价值”警告没有显示出来。

How can I get the same warnings as displayed in Eclipse? 如何获得与Eclipse中显示的相同的警告? Thanks for help :) 感谢帮助 :)

Edit for clarity: I would like to display the same warnings as in eclipse, not other bugs as reported by FindBugs, PMD or checkstyle 为清晰起见编辑:我想显示与eclipse中相同的警告,而不是FindBugs,PMD或checkstyle报告的其他错误

I finally found a solution for my problem, so I wanna share it :) I added this to my pom-file, and now the warnings show up during compilation with maven, and I was able to include them to jenkins using the warnings plugin. 我终于为我的问题找到了一个解决方案,所以我想分享它:)我把它添加到我的pom文件中,现在警告出现在与maven编译期间,我能够使用warnings插件将它们包含到jenkins中。 The important thing I missed in my first attempts was, that the plugins need to be under pluginManagement. 我在第一次尝试中遗漏的重要一点是,插件需要在pluginManagement下。

The warnings are generated by a specific compiler, to prevent the error "no such compiler: eclipse" the dependency to the plexus-compiler is included. 警告由特定的编译器生成,以防止错误“没有这样的编译器:eclipse”包含对plexus编译器的依赖。

Hope this works for others as well :) 希望这对其他人也有效:)

    <build>
        <pluginManagement>
                <plugins>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <compilerId>eclipse</compilerId>
                            <source>1.6</source>
                            <target>1.6</target>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>org.codehaus.plexus</groupId>
                                <artifactId>plexus-compiler-eclipse</artifactId>
                                <version>1.8.6</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
         </pluginManagement>
   </build>

Better than the eclipse warnings, you could use a static analysis tool like PMD and the right rules. 比日食警告更好,你可以使用像PMD这样的静态分析工具和正确的规则。 Check the Maven PMD Plugin 检查Maven PMD插件

Examples of rules you could use: 您可以使用的规则示例:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM