我刚刚使用gradle 3.4和gradle-script-kotlin 0.6移动了我的构建脚本以使用gradle-script-kotlin。
我可以使用构建脚本来生成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没有任何建议吗?
由于
答案 0 :(得分:0)
Application插件不是正确的地方,它用于生成运行脚本。要在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 Script构建文件中