Gradle - checkstyle config file in separate jar

303 views
Skip to first unread message

Haroon Sheikh

unread,
Dec 19, 2016, 10:10:05 AM12/19/16
to checkstyle
Currently I have checkstyle config under a separate jar (dependency).

This is what I have in my build.gradle

apply plugin: 'checkstyle'

configurations {
    checkstyleDep
}

dependencies {
    checkstyleDep 'com.mycompany.tools:buildtools:1.0.1'
    compile 'com.puppycrawl.tools:checkstyle:7.3'
}

I've tried passing in the `getClass().getResourceAsStream("config/checkstyle/checkstyle.xml")` as the configFile but that's not working.



Haroon Sheikh

unread,
Dec 19, 2016, 10:12:08 AM12/19/16
to checkstyle
I've managed to to get working with using the following config:

checkstyle {
    ignoreFailures = true
    showViolations = true
    config = resources.text.fromArchiveEntry(configurations.checkstyleDep, 'config/checkstyle/checkstyle.xml')
}

However, the problem is `fromArchiveEntry` is incubating and I would like to know whether there a better alternative for referencing the config file from a dependency.

Roman Ivanov

unread,
Dec 20, 2016, 10:13:01 PM12/20/16
to Haroon Sheikh, checkstyle
Hi Haroon,

config could be loaded by file path, url, or path in classpath on runtime.

if jar where your config is located is not loaded to classpath during runtime of checkstyle - you need to load it with some other tools.

if jar where config is located is loaded to classpath during run of checkstyle you can simply do 
config = 'config/checkstyle/checkstyle.xml'

Checkstyle will try to load from url, from file,  then try classpath.

thanks,
Roman Ivanov

--
You received this message because you are subscribed to the Google Groups "checkstyle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to checkstyle+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages