用gradle-script-kotlin构建一个可执行的fat jar

我刚刚把我的构建脚本移到使用gradle-script-kotlin,使用gradle 3.4和gradle-script-kotlin 0.6。

我可以得到构建脚本生成一个jar,但清单不包括主类名称。 我已经根据我发现的其他帖子,尝试了Kt和KT的主类名。

构建脚本如下所示:

/* * Copyright 2017 SixRQ Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ group = "com.sixrq" version = "1.0-SNAPSHOT" buildscript { repositories { maven { setUrl("http://dl.bintray.com/kotlin/kotlin-eap-1.1") } gradleScriptKotlin() } dependencies { classpath(kotlinModule("gradle-plugin")) } } plugins { application groovy java } apply { plugin("kotlin") } repositories { maven { setUrl("http://dl.bintray.com/kotlin/kotlin-eap-1.1") } mavenCentral() } dependencies { compile(kotlinModule("stdlib")) compile("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1-M04") compile("org.codehaus.groovy:groovy-all:2.3.11") compile("com.fasterxml.jackson.module:jackson-module-kotlin:2.7.4") testCompile("org.spockframework:spock-core:1.0-groovy-2.4") testCompile("junit:junit:4.11") } configure<ApplicationPluginConvention> { mainClassName = "com.sixrq.kaxb.main.SchemaGenerator" } 

我也想创建一个包含运行时依赖关系的胖jar包,我可以看到groovy编译脚本的大量例子,但是对于gradle-script-kotlin没有任何建议吗?

谢谢

应用程序插件不是正确的地方,这是用于生成运行脚本。 为了在jar中设置主类,你需要使用下面的代码:

 import org.gradle.jvm.tasks.Jar 

 val jar: Jar by tasks jar.apply { manifest.attributes.apply { put("Main-Class", "com.sixrq.kaxb.main.SchemaGenerator") } } 

在Kotlin脚本构建文件中