Conversation
marshallpierce
commented
Aug 28, 2020
- Include support for building Kotlin w/ kotlinter code format checking
- Include a starting point for a Clikt-based CLI (see https://ajalt.github.io/clikt/)
- Include support for building Kotlin w/ kotlinter code format checking - Include a starting point for a Clikt-based CLI (see https://ajalt.github.io/clikt/)
| @@ -0,0 +1,42 @@ | |||
| plugins { | |||
| kotlin("jvm") version "1.4.0" | |||
| id("org.jmailen.kotlinter") version "3.0.2" | |||
There was a problem hiding this comment.
Will fail the build if your kotlin isn't formatted right, and you can use this to auto-fix it:
./gradlew formatKotlin
| plugins { | ||
| kotlin("jvm") version "1.4.0" | ||
| id("org.jmailen.kotlinter") version "3.0.2" | ||
| id("com.github.johnrengelman.shadow") version "6.0.0" |
There was a problem hiding this comment.
produces "fat jars" that have dependencies bundled in. This is a sort of regrettable way to package software, but it's probably the simplest for your users.
| } | ||
|
|
||
| application { | ||
| mainClassName = "com.foo.unmls.UnmlsGraphTool" |
There was a problem hiding this comment.
this is used by the shadow plugin when generating the "shaded" aka fat jar to know which class to invoke by default
| @@ -0,0 +1,42 @@ | |||
| plugins { | |||
There was a problem hiding this comment.
This file is actually itself kotlin (in script flavor, hence .kts instead of .kt)
| @@ -0,0 +1,5 @@ | |||
| distributionBase=GRADLE_USER_HOME | |||
There was a problem hiding this comment.
these and the other gradle files are auto-generated
| init { | ||
| subcommands( | ||
| Foo(), | ||
| Bar() |
| } | ||
|
|
||
| private class Foo : CliktCommand() { | ||
| private val widgetSize: Int by option().int().required() |
There was a problem hiding this comment.
this will produce a --widget-size CLI param automatically (can customize the name, but by default it goes off of the property name)
| private val widgetSize: Int by option().int().required() | ||
|
|
||
| override fun run() { | ||
| println("Size $widgetSize widget") |
| The `umls-to-graph` code uses Gradle to handle dependencies (see the `build.gradle.kts` file for details). Run the code from Eclipse or IntelliJ, or compile a jar: | ||
|
|
||
| ``` | ||
| ./gradlew assemble |
There was a problem hiding this comment.
this is the default task that's set up for "do whatever tasks are necessary to produce the build artifacts that you might publish or otherwise use directly". The key task running under the hood is the shadowJar task, provided by the shadow plugin.
|
|
||
| object UnmlsGraphTool { | ||
| @JvmStatic | ||
| fun main(args: Array<String>) { |
There was a problem hiding this comment.
For iterative development you might set up an IDE "run configuration" that runs this class with your chosen parameters. Or, if you're CLI focused, you might:
./gradlew run --args='foo --widget-size 1'
Or if you don't want gradle in the way, but just want to work directly with the jar:
./gradlew shadowJar
java -jar build/libs/umls-to-graph-all.jar foo --widget-size=1
Or to get fancier...
In one terminal, run gradle in "watch mode". Whenever input files change, it will redo the necessary build steps to generate the shadow jar constantly, so it will keep running until you kill it. Also note that we are abbreviating shadowJar as shJ, and gradle is ok with that since shJ is an unambiguous abbreviation. c would not be, since it could be clean or check, but ch (for check, which runs tests) would be ok.
./gradlew shJ --continuous
In another:
java -jar build/libs/umls-to-graph-all.jar foo --widget-size=1
| @@ -0,0 +1,42 @@ | |||
| plugins { | |||
| kotlin("jvm") version "1.4.0" | |||
There was a problem hiding this comment.
the kotlin plugin applies the java plugin, so no need to do that separately. (Java and Kotlin source will both be compiled)
| kotlin("jvm") version "1.4.0" | ||
| id("org.jmailen.kotlinter") version "3.0.2" | ||
| id("com.github.johnrengelman.shadow") version "6.0.0" | ||
| application |
There was a problem hiding this comment.
configures tasks to produce output appropriate for an application, rather than a library (which we actually are disabling below since we want a shaded fat jar), and the run task to run the main() method of the class specified below
| } | ||
|
|
||
| repositories { | ||
| jcenter() |