Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven 我是否可以捆绑checkstyle的导入控制文件,以便在使用我们的checkstyle的所有项目中使用?_Maven_Checkstyle_Maven Checkstyle Plugin - Fatal编程技术网

Maven 我是否可以捆绑checkstyle的导入控制文件,以便在使用我们的checkstyle的所有项目中使用?

Maven 我是否可以捆绑checkstyle的导入控制文件,以便在使用我们的checkstyle的所有项目中使用?,maven,checkstyle,maven-checkstyle-plugin,Maven,Checkstyle,Maven Checkstyle Plugin,我试图将导入控制添加到checkstyle中,这样导入控制文件就存在于生成checstyle.xml文件的项目中,而不是我们以后构建的项目中 我们有一个特定的gradle项目,在该项目中定义了所有规则,并在该项目中定义了import-control.xml。我的问题是,当我尝试在另一个使用此checkstyle的项目上运行mvn clean install时,它会尝试在该项目中定位import-control.xml 我在checkstyle.xml中进行了以下配置: <m

我试图将导入控制添加到checkstyle中,这样导入控制文件就存在于生成checstyle.xml文件的项目中,而不是我们以后构建的项目中

我们有一个特定的gradle项目,在该项目中定义了所有规则,并在该项目中定义了import-control.xml。我的问题是,当我尝试在另一个使用此checkstyle的项目上运行mvn clean install时,它会尝试在该项目中定位import-control.xml

我在checkstyle.xml中进行了以下配置:

        <module name="ImportControl">
            <property name="file" value="import-control.xml"/>
        </module>
    <module name="ImportControl">
        <property name="file" value="${config_loc}/config/import_control.xml"/>
    </module>

import-control.xml放在checkstyle.xml旁边

谁能告诉我需要做什么,这样我才能告诉maven这个文件存在于我们的checkstyle项目中,而不是正在构建的根项目中

我收到的错误是: 无法初始化模块TreeWalker-无法初始化模块ImportControl-属性“file”的非法值“import control.xml”找不到:import-control.xml

第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>```
    <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>

org.apache.maven.plugins
maven checkstyle插件
3.1.0
检查样式
过程源
检查
项目A/**/*
checkstyle.xml
真的
假的
真的
真的
公司。支票样式
公司支票样式
0.2-1快照
```

再次感谢barfuin,看起来${config_loc}就是答案,但我们还需要一件事才能让它完全工作

因此,为了从checkstyle项目中添加资源,如在这个文件import_control.xml中,我在我的checkstyle.xml中做了如下操作:

        <module name="ImportControl">
            <property name="file" value="import-control.xml"/>
        </module>
    <module name="ImportControl">
        <property name="file" value="${config_loc}/config/import_control.xml"/>
    </module>

我还需要做的是补充:

<propertyExpansion>config_loc=</propertyExpansion>
config\u loc=
在我的pom.xml配置中,这解决了未定义config_loc以及checkstyle将文件作为资源查找的问题,并为我提供了以下pom.xml配置:

      <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>```
    <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>

org.apache.maven.plugins
maven checkstyle插件
检查样式
过程源
检查
项目A/**/*
checkstyle.xml
真的
假的
真的
真的
配置位置=
公司。支票样式
公司支票样式
0.2-1快照

Try
刚刚尝试过,但显然未定义${config\u loc}。有什么方法可以/应该定义它吗?但是谢谢你给我找个地方看这个!它需要一个绝对路径,例如
C:/path/to/import control.xml
。Maven似乎不像大多数IDE插件那样定义变量。您可以尝试手动设置绝对路径,只是为了验证其余路径是否有效。嗯。。。我想一个解决方案应该是在buildproject中解压checkstyle jar,并给出一个到目标的相对路径,因为它适用于不同用户计算机上的多个项目,所以路径不能是静态的。但是谢谢你的帮助!