使用PMD Maven分析Javascript [英] Analyzing Javascript with PMD Maven
问题描述
我目前正在尝试将PMD作为我们公司可以使用的静态分析工具。我已经分析了没有任何问题的Java文件,但我似乎无法使用Javascript,每次我执行pmd:pmd它只是再次分析java文件。无论如何,这是我的POM.xml的片段:
I'm currently trying out PMD as a possible static analysis tool that our company can use. I've analyzed Java files with no problems whatsoever, but I couldn't seem to do it with Javascript, everytime I execute pmd:pmd it just analyses java files again. Anyways, here is a snippet of my POM.xml:
*使用Maven 3.3.1
*Using Maven 3.3.1
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<sources>
${basedir}/src/main/webapp/js
</sources>
</configuration>
<executions>
<execution>
<goals>
<goal>add-source</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.7</version>
<configuration>
<language>javascript</language>
<rulesets>
<ruleset>ecmascript-basic</ruleset>
<ruleset>ecmascript-braces</ruleset>
<ruleset>ecmascript-unnecessary</ruleset>
</rulesets>
<includes>
<include>**/*.js</include>
</includes>
</configuration>
</plugin>
</plugins>
</reporting>
所以我只是按照这个但似乎无法使它工作。如果我错过了一些必要的设置/配置,你能告诉我吗? TIA。
So I just followed the instructions indicated in this but can't seem to make it work. Can you guys please tell me if I'm missing some required setups / configurations ? TIA.
推荐答案
您的配置是正确的(假设缺少< plugins>
标签只是编辑问题)。很可能你没有运行正确的maven目标。
Your configuration is correct (assuming the missing <plugins>
tags are simply edit issues). Most probably you are not running the proper maven targets.
使用当前配置,PMD将在站点生成期间作为报告运行,即 mvn网站
。但是,如果这样做, build-helper-maven-plugin:add-source
目标将无法运行,并且找不到源。
With your current configuration, PMD will just be run as a report during site generation, that is mvn site
. However, if doing that, the build-helper-maven-plugin:add-source
target would not run, and the sources would not be found.
最基本(无用)的方法是简单地调用 mvn generate-sources site
。
The most basic (useless) way around this, is simply calling mvn generate-sources site
.
您可以通过将插件配置更改为 mvn site
,自动运行 add-source
如下:
You can have the add-source
run automatically on mvn site
by changing the plugin config as follows:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>config-js</id>
<phase>pre-site</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>${basedir}/src/main/javascript</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
此处,阶段
设为 pre-site
将执行挂钩到 site
生命周期的开头。
Here, the phase
set to pre-site
does the magic of hooking the execution to the beginning of the site
lifecycle.
如果您希望能够使用 mvn pmd:pmd
或 mvn pmd运行PMD:检查
,那么你的配置应该略有不同。 PMD插件不应该是< reporting>
部分的一部分,而是< build>
的一部分。不幸的是,PMD maven插件并没有将自己挂钩到生命周期事件,所以在这种情况下,我们必须手动确保 build-helper-maven-plugin:add-source
运行。再一次,我们可以使用 mvn generate-sources pmd:pmd
If you want to be able to run PMD using mvn pmd:pmd
or mvn pmd:check
, then your configuration should be slightly different. The PMD plugin should not be part of the <reporting>
section, but part of <build>
. Unfortunately, the PMD maven plugin doesn't hook itself to a lifecycle event, so on this case, we have to manually make sure build-helper-maven-plugin:add-source
is run. Once again, we can do so with mvn generate-sources pmd:pmd
这篇关于使用PMD Maven分析Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!