【问题标题】:Building an executable fat jar with gradle-script-kotlin使用 gradle-script-kotlin 构建可执行的 fat jar
【发布时间】:2017-01-19 13:50:50
【问题描述】:

我刚刚将构建脚本转移到使用 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 没有,有什么建议吗?

谢谢

【问题讨论】:

    标签: gradle kotlin


    【解决方案1】:

    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 脚本构建文件中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-29
      • 2017-06-07
      • 2014-12-15
      • 2021-01-21
      • 2017-11-30
      • 1970-01-01
      • 2020-07-29
      • 2016-02-08
      相关资源
      最近更新 更多