Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for 3rd-party reporters? #45

Closed
autonomousapps opened this issue Mar 25, 2018 · 7 comments
Closed

Support for 3rd-party reporters? #45

autonomousapps opened this issue Mar 25, 2018 · 7 comments

Comments

@autonomousapps
Copy link
Contributor

See pinterest/ktlint#176.

@jeremymailen
Copy link
Owner

Would it work for you if I directly support https://github.com/mcassiano/ktlint-html-reporter (with the author's permission of course) as reporter for 'html'?

I could make it extensible with providers the way rule sets are, but I suspect it is a less common use case and I'm shooting for "simply works out of the box" for the most part with this gradle plugin.

@autonomousapps
Copy link
Contributor Author

That would work for me, and I think it makes sense in this case. An html reporter would be super useful out of the box.

@shyiko
Copy link

shyiko commented Mar 25, 2018

Guys,
this is not stated in the ktlint's README (even though it should) but reporters are loaded using ServiceLoader same as rulesets. In other words, as long as jar containing Reporter implementation is on the classpath it will be loaded.
This is why something like

dependencies {
    ktlint "com.github.shyiko:ktlint:0.20.0"
    ktlint "com.github.mcassiano:ktlint-html-reporter:master-SNAPSHOT"
}

task ktlint(type: JavaExec, group: "verification") {
    description = "Check Kotlin code style."
    classpath = configurations.ktlint
    main = "com.github.shyiko.ktlint.Main"
    args "--reporter=html", "src/**/*.kt" # notice that no artifact=... is needed
}

should work (same applies to Maven). By extension, https://github.com/jeremymailen/kotlinter-gradle#custom-rules can be used for the same purpose.
This is for your information only. I'm not advocating any particular implementation (or a lack thereof).

@mcassiano
Copy link

Hey! I was going to publish this later on but there were some things I was trying to investigate further.

I'm not sure I was doing something wrong but loading the reporter from jar was not working. My guess is that in line 378 the wrong id is being used to query the map (it's using the id passed on as an argument, which in this case is a path), when it should be using ReporterProvider.id. I didn't have time to check if that's what's happening but I'd gladly open an issue and PR to ktlint if that's the case. (ping @shyiko)

What I did to use this in a project was loading the jar as a ruleset (it only loads the jar) and then passing ReporterProvider.id of my reporter as an option (--reporter=html,output=${buildDir}/ktlint.html) which, I know, IS VERY HACKY. haha

@mcassiano
Copy link

Oh, I see, you fixed the bug! Nice.

@jeremymailen
Copy link
Owner

@autonomousapps
Copy link
Contributor Author

Thanks!

Configuring it now, and I'm considering elaborating on the solution to allow for a single report for all source sets, and/or a single report for multiple modules. Just to make configuring Jenkins a bit easier. Will update you if that ever happens :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants