G
G
glodev2020-02-28 15:20:48
gradle
glodev, 2020-02-28 15:20:48

How to set start class in gradle (Kotlin, KotlinDSL, Gradle)?

There is a build.gradle

import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet

plugins {
    java
    kotlin("jvm") version "1.3.70-eap-184"
    application
}
    group = "dev.glo"
    version = "1.0-SNAPSHOT"
    application {
        mainClassName = "dev.glo.Main"
    }
    repositories {
        maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") }
        mavenCentral()
    }

    dependencies {
        implementation(kotlin("stdlib-jdk8"))
        testImplementation(kotlin("test"))
        implementation("com.google.guava", "guava", "28.2-jre")

    }

    sourceSets["main"].withConvention(KotlinSourceSet::class) { kotlin.srcDir("src/main/dev/glo/Main") }
    configure<JavaPluginConvention> {
        sourceCompatibility = JavaVersion.VERSION_1_8
    }

    tasks {
        compileKotlin {
            kotlinOptions.jvmTarget = "1.8"
        }
        compileTestKotlin {
            kotlinOptions.jvmTarget = "1.8"
        }
    }


The vastness of the Internet did not suggest a solution to the issue, unfortunately, many solutions are different, but do not work. (The reason, as I understand it, is that basically the solutions are not written in kotlinDSL and not under Kotlin)

5e5907dceabc4516294681.png

no main manifest attribute, in D:\IdeaProjects\testGradle\build\libs\testGradle-1.0-SNAPSHOT.jar

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
glodev, 2020-03-04
@glodev

tasks {
        compileKotlin {
            kotlinOptions.jvmTarget = "1.8"
        }
        compileTestKotlin {
            kotlinOptions.jvmTarget = "1.8"
        }
        jar {
            manifest {
                attributes(
                    mapOf(
                        "Implementation-Title" to project.name,
                        "Implementation-Version" to project.version,
                        "Main-Class" to mainClassNameProject
                    )
                )
            }

        }
    }

I asked myself, I will answer)

K
koperagen, 2020-02-28
@koperagen

Try changing
mainClassName = "dev.glo.Main"
to
mainClassName = "dev.glo.MainKt"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question