advent-of-code-kotlin-template icon indicating copy to clipboard operation
advent-of-code-kotlin-template copied to clipboard

Command line run

Open dvlp-r opened this issue 1 year ago • 4 comments

Hi, I have downloaded your template and I am struggling about how to run the Day01.kt file from command line.

Gradle build -> gradle run does not work since there is no a run task in the build script.

Thank you in advance for your help.

dvlp-r avatar Dec 01 '23 16:12 dvlp-r

Any reason why you don't just use the intellij run icon next to main()? image

If you still want/need to use gradle, you can reconfigure the build.gradle.kts and then use gradle run.

plugins {
    kotlin("jvm") version "1.9.20"
    application
}

application {
    mainClass = "Day01Kt"
}

MaaxGr avatar Dec 01 '23 22:12 MaaxGr

Hi @MaaxGr , thanks for your response. yes, sometimes I code in codespaces from iPad and I need to use command line. I knew this alternative but I was interested in knowing the underling command used by IntelliJ to build and run, without the need of modifying anything in the template, so to be able to use it both in intelllij and in other envs.

dvlp-r avatar Dec 01 '23 23:12 dvlp-r

This template provides a minimal setup for running Advent of Code solutions via IDE.

Using @MaaxGr suggestion, we can go further and parametrize the mainClass with:

plugins {
    kotlin("jvm") version "1.9.20"
    application
}

sourceSets {
    main {
        kotlin.srcDir("src")
    }
}

application {
    mainClass = providers.gradleProperty("day").map { "Day${it}Kt" }
}

tasks {
    wrapper {
        gradleVersion = "8.5"
    }
}

and run it with:

./gradlew run -Pday="01"

hsz avatar Dec 02 '23 06:12 hsz

I have the same usecase as @dvlp-r, using codespaces while on the run, so running the program through the CLI is essential. I like your suggestion @hsz.

mikaello avatar Dec 03 '23 06:12 mikaello