【问题标题】:gradle - checkstyle config file in separate jargradle - 单独 jar 中的 checkstyle 配置文件
【发布时间】:2013-07-17 12:01:18
【问题描述】:

我正在尝试强制 checkstyle 插件使用存储在不同 jar 文件中的 xml 配置(作为依赖项)。

我创建了一个仅包含该配置文件的包。

在 build.gradle 我有以下配置:

apply plugin: 'checkstyle'

checkstyle {
    checkstyleMain {
        classpath += configurations.checkstyleDep
    }
    checkstyleTest {
        classpath += configurations.checkstyleDep
    }
    configFile = new File(getClass().getResource("/checkstyle.xml").toURI())
    println(configFile)
}

configurations {
    checkstyleDep
}

dependencies {
    checkstyleDep "com.example:checkstyle-common:1.0"
}

不幸的是,这不会导致 gradle 看到依赖项。

我的代码有什么问题?有没有更好的方法来做到这一点?

【问题讨论】:

  • 'com.example:checkstyle-common:1.0' jar 在您的存储库中可用吗?
  • 是的,它是 - 我已将它放入本地 maven repo 并正确下载。
  • 您是否尝试将其添加为 buildscript 依赖项?

标签: java gradle build.gradle


【解决方案1】:

从 gradle 2.2 开始,您可以将配置 xml 设置为字符串。

我做到了

checkstyle {
    config = getClass().getResource("checkstyle.xml").text
}

【讨论】:

    【解决方案2】:

    考虑这种方法(Gradle 5.0):

    # add the checkstyle plugin
    plugins {
        id "java"
        id "checkstyle"
    }
    
    # load the dependency that has the rules
    configurations {
        checkstyleRules
    }
    
    dependencies {
        checkstyleRules "com.github.ngeor:checkstyle-rules:3.3.0"
    }
    
    # configure checkstyle
    checkstyle {
        toolVersion "8.24"
        config project.resources.text.fromArchiveEntry(configurations.checkstyleRules, "com/github/ngeor/checkstyle.xml")
    }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 2014-03-29
      • 2018-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多