G
G
glodev2020-03-24 14:35:07
gradle
glodev, 2020-03-24 14:35:07

How to create a start build in gradle (Kotlin, KotlinDSL, Gradle)?

The question is very simple, how do I use 3 technologies to build a project.

Referring to the github https://github.com/gradle/kotlin-dsl-samples/tree/...

Let's take an example, we get an error, the main class is not defined in the manifest, we define the main class well, we get an error that the method must be static. Let's make a static function out of the class (analogous to a static method in java), we will get a runtime error.

Please help and show an example of word hels on a stack of 3 technologies Kotlin, KotlinDSL, Gradle

Addition: startup script, execute task build

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"
    val mainClassNameProject = "dev.glo.MainKt"
    application.mainClassName = "$mainClassNameProject"
    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") }
    configure<JavaPluginConvention> {
        sourceCompatibility = JavaVersion.VERSION_1_8
    }

    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
                    )
                )
            }

        }
    }

Link to full project

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tony, 2020-12-16
@TonyHunt

Sketched a Hello World example in Kotlin and how to get a JAR file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question