M
M
MechanicZelenyy2018-08-18 15:53:16
gradle
MechanicZelenyy, 2018-08-18 15:53:16

How to create a task to run an application using Gradle Kotlin DSL?

Good afternoon.
Decided to try Gradle Kotlin DLS.
I have a program with several entry points, and to run them, I made separate tasks of the form:

task runMain(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = "ru.mipt.npm.mcengine.MainKt"
    standardInput = System.in
}

Now I am trying to do like this:
tasks.create<JavaExec>("runMain"){
    classpath = java.sourceSets["main"].runtimeClasspath
    main = "ru.mipt.npm.mcengine.MainKt"
    standardInput = System.`in`
}

However, there is some problem with the classpath, it doesn't work with an error:
Script compilation error:

  Line 38:     classpath = java.sourceSets["main"].runtimeClasspath
                                ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
                                    public val Project.sourceSets: SourceSetContainer defined in org.gradle.kotlin.dsl

What to do? Studying the documentation did not lead me to an answer.
PS I know about the application plugin, it does not suit me.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question