我试图以一种方式将导入控制添加到我们的checkStyle中,以至于项目中存在import-control文件,从而使checstyle.xml文件而不是我们以后构建的项目中存在在。
我们有一个特定的gradle项目,我们在其中定义了所有规则,而在该项目中,我们的intiment-control.xml。我的问题是,当我尝试在另一个使用此checkStyle的项目上运行MVN CLEAN安装时,它试图在该项目中找到Import-control.xml。
我在checkstyle.xml中进行了以下配置:
<module name="ImportControl">
<property name="file" value="import-control.xml"/>
</module>
和import-control.xml位于checkstyle.xml旁边。
谁能告诉我我需要做的事情,以便我可以告诉Maven这个文件存在于我们的CheckStyle项目中,而不是正在构建的根项目中?
错误我遇到的错误是:无法初始化模块树漫步者 - 无法初始化模块importcontrol-非法值'import -control.xml'属于属性'文件'无法找到:import-control.xml
在V 2.17
中无法加载import-control.xml:无法找到文件:/c://import-control.xml: import-control.xml
我尝试过的内容:升级CheckStyle版本为3.1.0(我们曾经有2.17(使用Import-control.xml,但不起作用。试图阅读文档和代码,但没有帮助。
感谢您的任何帮助
稍后写给您/Mårten
MVN配置:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>do checkstyle</id>
<phase>process-sources</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>projectA/**/*</includes>
<configLocation>checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failOnViolation>false</failOnViolation>
<failsOnError>true</failsOnError>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>company.checkstyle</groupId>
<artifactId>company-checkstyle</artifactId>
<version>0.2-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>```
再次感谢barfuin,似乎是$ {config_loc}是答案,但我们还需要一件事才能完全工作。
因此,要添加CheckStyle项目中的资源,就像在此文件中一样
<module name="ImportControl">
<property name="file" value="${config_loc}/config/import_control.xml"/>
</module>
我还需要做的是添加:
<propertyExpansion>config_loc=</propertyExpansion>
在我的pom.xml配置中,这解决了未定义的config_loc的问题,并且要查找文件作为资源,并给了我以下pom.xml configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>do checkstyle</id>
<phase>process-sources</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>projectA/**/*</includes>
<configLocation>checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failOnViolation>false</failOnViolation>
<failsOnError>true</failsOnError>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<propertyExpansion>config_loc=</propertyExpansion>
</configuration>
<dependencies>
<dependency>
<groupId>company.checkstyle</groupId>
<artifactId>company-checkstyle</artifactId>
<version>0.2-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>