相关疑难解决方法(0)

使用Gradle和Kotlin构建一个可自我执行的jar

我已经编写了一个简单的kotlin源文件以便开始使用,还有一个gradle脚本文件.但我无法弄清楚如何将主要功能添加到清单中,以便jar可以自行执行.

这是我的build.gradle脚本:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.9.66'
    }
}
apply plugin: "kotlin"
repositories {
    mavenCentral()
}
dependencies {
    compile 'org.jetbrains.kotlin:kotlin-stdlib:0.9.66'
}

jar {
    manifest {
        attributes 'Main-Class': 'com.loloof64.kotlin.exps.ExpsPackage'
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的com.loloof64.kotlin.exps.Multideclarations.kt

package com.loloof64.kotlin.exps

class Person(val firstName: String, val lastName: String) {
    fun component1(): String {
        return firstName
    }
    fun component2(): String {
        return lastName
    }
}

fun main(args: Array < String > ) {
    val(first, last) = Person("Laurent", "Bernabé")
    println("First name : $first - Last …
Run Code Online (Sandbox Code Playgroud)

gradle kotlin

43
推荐指数
3
解决办法
2万
查看次数

如何使用gradle kotlin脚本创建胖罐

正如标题所述,我想知道如何修改它gradle.build.kts以便创建一个独特jar的所有依赖项(包括kotlin lib)的任务.

我在Groovy中找到了这个示例:

//create a single Jar with all dependencies
task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',
            'Implementation-Version': version,
            'Main-Class': 'com.mkyong.DateUtils'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在kotlin中写出来,除了:

task("fatJar") {

}
Run Code Online (Sandbox Code Playgroud)

kotlin build.gradle build.gradle.kts gradle-kotlin-dsl

29
推荐指数
4
解决办法
1万
查看次数

如何为 Kotlin (Gradle) 构建导入 ShadowJar 插件?

构建失败:

thufir@dur:~/NetBeansProjects/kotlin_dsl$ 
thufir@dur:~/NetBeansProjects/kotlin_dsl$ gradle clean run 

> Configure project : 
e: /home/thufir/NetBeansProjects/kotlin_dsl/build.gradle.kts:4:12: Unresolved reference: github


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'kotlin_dsl'.
> Could not open cache directory 74ykawxta6db3b2bfk9grjikp (/home/thufir/.gradle/caches/4.3.1/gradle-kotlin-dsl/74ykawxta6db3b2bfk9grjikp).
   > Internal error: unable to compile script, see log for details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD …
Run Code Online (Sandbox Code Playgroud)

build gradle kotlin shadowjar gradle-kotlin-dsl

4
推荐指数
1
解决办法
6168
查看次数