Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用gradle脚本kotlin构建可执行的胖jar_Gradle_Kotlin - Fatal编程技术网

使用gradle脚本kotlin构建可执行的胖jar

使用gradle脚本kotlin构建可执行的胖jar,gradle,kotlin,Gradle,Kotlin,我刚刚将构建脚本移到使用gradle脚本kotlin,使用gradle 3.4和gradle脚本kotlin 0.6 我可以让构建脚本生成一个jar,但清单中不包含主类名。根据我找到的其他帖子,我尝试了在末尾使用Kt和Kt的主类名 构建脚本如下所示: /* * Copyright 2017 SixRQ Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may n

我刚刚将构建脚本移到使用gradle脚本kotlin,使用gradle 3.4和gradle脚本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"
}
/*
*版权所有2017 SixRQ有限公司。
*
*根据Apache许可证2.0版(以下简称“许可证”)获得许可;
*除非遵守许可证,否则不得使用此文件。
*您可以通过以下方式获得许可证副本:
*
*        http://www.apache.org/licenses/LICENSE-2.0
*
*除非适用法律要求或书面同意,软件
*根据许可证进行的分发是按“原样”进行分发的,
*无任何明示或暗示的保证或条件。
*请参阅许可证以了解管理权限和权限的特定语言
*许可证下的限制。
*/
group=“com.sixrq”
version=“1.0-SNAPSHOT”
构建脚本{
存储库{
maven{setUrl(“http://dl.bintray.com/kotlin/kotlin-eap-1.1")  } 
gradleScriptKotlin()
} 
依赖关系{
类路径(kotlinModule(“gradle插件”))
}
}
插件{
应用
棒极了
JAVA
}
申请{
插件(“kotlin”)
}
存储库{
maven{setUrl(“http://dl.bintray.com/kotlin/kotlin-eap-1.1") }
mavenCentral()
}
依赖关系{
编译(kotlinModule(“stdlib”))
编译(“org.jetbrains.kotlin:kotlin gradle plugin:1.1-M04”)
编译(“org.codehaus.groovy:groovy-all:2.3.11”)
编译(“com.fasterxml.jackson.module:jackson模块kotlin:2.7.4”)
testCompile(“org.spockframework:spock核心:1.0-groovy-2.4”)
testCompile(“junit:junit:4.11”)
}
配置{
mainClassName=“com.sixrq.kaxb.main.SchemaGenerator”
}
我还想创建一个包含运行时依赖项的胖jar,对于groovy构建脚本,我可以看到很多这样的例子,但是对于gradle脚本kotlin,没有任何建议


谢谢

应用程序插件不是正确的位置,它用于生成运行脚本。为了在jar中设置主类,您需要使用以下命令:

import org.gradle.jvm.tasks.Jar

在Kotlin脚本构建文件中

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