exception - Groovy Codenarc.xml org.xml.sax.SAXParseException xsi :schemaLocation not associated with element type ruleset not bound

标签 exception groovy gradle xsi codenarc

我正在使用 Gradle 2.3 并且项目有 Groovy 代码。对于静态代码分析,我使用的是 Codenarc(即项目文件夹有“config/codenarc/codenarc.xml”文件)。

在 build.gradle/GRADLE_HOME/init.d/top-level.gradle 文件中,我有:

apply plugin: 'codenarc'

   codenarc {
     ignoreFailures = true
     configFile = file("config/codenarc/codenarc.xml")
   }

但是在编译这个项目时,我得到了以下错误。
13:49:00 :codenarcAcceptanceTest UP-TO-DATE
13:49:01 :codenarcIntegrationTest FAILED
13:49:01 
13:49:01 FAILURE: Build failed with an exception.
13:49:01 
13:49:01 * What went wrong:
13:49:01 Execution failed for task ':codenarcIntegrationTest'.
13:49:01 > org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 173; The prefix "xsi" for attribute "xsi:schemaLocation" associated with an element type "ruleset" is not bound.
13:49:01 
13:49:01 * Try:
13:49:01 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
13:49:01 
13:49:01 BUILD FAILED

codenarc.xml 文件中的文件内容为:
<ruleset xsi:schemaLocation="http://codenarc.org/ruleset/1.0 http://codenarc.org/ruleset-schema.xsd" xsi:noNamespaceSchemaLocation="http://codenarc.org/ruleset-schema.xsd">
   <description>Sample rule set</description>
   <ruleset-ref path="rulesets/basic.xml"/>
   <ruleset-ref path="rulesets/braces.xml">
      <rule-config name="IfStatementBraces">
         <property name="priority" value="3"/>
      </rule-config>
   </ruleset-ref>
   <ruleset-ref path="rulesets/concurrency.xml"/>
  <ruleset-ref path="rulesets/convention.xml"/>
   <ruleset-ref path="rulesets/design.xml"/>
   <ruleset-ref path="rulesets/dry.xml">
      <rule-config name="DuplicateStringLiteral">
         <property name="doNotApplyToClassNames" value="*Spec"/>
      </rule-config>
      <rule-config name="DuplicateNumberLiteral">
         <property name="doNotApplyToClassNames" value="*Spec"/>
      </rule-config>
      <rule-config name="DuplicateMapLiteral">
         <property name="doNotApplyToClassNames" value="*Spec"/>
      </rule-config>
      <rule-config name="DuplicateListLiteral">
         <property name="doNotApplyToClassNames" value="*Spec"/>
      </rule-config>
   </ruleset-ref>
   <ruleset-ref path="rulesets/exceptions.xml"/>
   <ruleset-ref path="rulesets/formatting.xml"/>
   <ruleset-ref path="rulesets/generic.xml"/>
   <ruleset-ref path="rulesets/grails.xml"/>
   <ruleset-ref path="rulesets/groovyism.xml"/>
   <ruleset-ref path="rulesets/imports.xml">
      <exclude name="MisorderedStaticImports"/>
   </ruleset-ref>
   <ruleset-ref path="rulesets/jdbc.xml"/>
   <ruleset-ref path="rulesets/junit.xml"/>
   <ruleset-ref path="rulesets/logging.xml"/>
   <ruleset-ref path="rulesets/naming.xml">
      <rule-config name="FieldName">
         <property name="ignoreFieldNames" value="log"/>
      </rule-config>
      <rule-config name="MethodName">
         <property name="doNotApplyToClassNames" value="*Spec"/>
      </rule-config>
      <exclude name="FactoryMethodName"/>
   </ruleset-ref>
   <ruleset-ref path="rulesets/security.xml">
      <exclude name="JavaIoPackageAccess"/>
   </ruleset-ref>
   <ruleset-ref path="rulesets/serialization.xml"/>
   <ruleset-ref path="rulesets/size.xml"/>
   <ruleset-ref path="rulesets/unnecessary.xml">
      <exclude name="UnnecessaryPackageReference"/>
   </ruleset-ref>
   <ruleset-ref path="rulesets/unused.xml"/>
</ruleset>

最佳答案

xml不知道是什么xsi您是否已将其添加为正确命名空间 url 的前缀。尝试以下标题:

<ruleset xmlns="http://codenarc.org/ruleset/1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://codenarc.org/ruleset/1.0 http://codenarc.org/ruleset-schema.xsd"
    xsi:noNamespaceSchemaLocation="http://codenarc.org/ruleset-schema.xsd">

关于exception - Groovy Codenarc.xml org.xml.sax.SAXParseException xsi :schemaLocation not associated with element type ruleset not bound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32028269/

相关文章:

java - 在 catch 子句中,当我没有创建任何异常时,如何记录异常实例

groovy - 如何让 Jenkins/Hudson 工作监视其他一些工作并决定是否建立?

android - Git使用Gradle必须忽略哪些文件?

android - 为什么每当我运行 Espresso 测试时都会启动新的 Gradle 构建?

asp.net-core - 如何使用 Serilog 抑制 'An unhandled exception has occurred while executing the request.' 日志消息

java - 在没有捕获的 try/catch/finally 中会发生什么?

java - 如何从 Java 调用 groovy 类的方法 - 字符串格式的方法名称和参数

groovy - 使用字符串作为 Groovy XML 解析器的代码

android - 如何在 Android Studio 中显示依赖关系树?

android - 我的 "MyException"显示 Toast 在抛出线程时会导致问题。我应该如何重新组织异常处理?