将Kotlin类指定为MANIFEST.MF中的Main-Class入口点?

时间:2017-11-05 11:57:02

标签: gradle jar kotlin uberjar shadowjar

我如何explicitly告诉shadowJar使用Kotlin文件作为结果uberJar的入口点? (或者,你喜欢胖JAR。)

笨拙地编辑META-INF/MANIFEST.MF并将其替换为zip文件(使用GUI将其放回):

thufir@dur:~/NetBeansProjects/kotlin/build/libs$ 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ ll
total 900
drwxrwxr-x 2 thufir thufir   4096 Nov  5 03:42 ./
drwxrwxr-x 8 thufir thufir   4096 Nov  5 03:42 ../
-rw-rw-r-- 1 thufir thufir 903184 Nov  5 03:42 kotlinAdder.jar
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ jar xf kotlinAdder.jar 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ ll
total 928
drwxrwxr-x  7 thufir thufir   4096 Nov  5 03:42 ./
drwxrwxr-x  8 thufir thufir   4096 Nov  5 03:42 ../
drwxrwxr-x  2 thufir thufir   4096 Nov  5 03:42 demo/
drwxrwxr-x 17 thufir thufir  12288 Nov  5 03:42 kotlin/
-rw-rw-r--  1 thufir thufir 903184 Nov  5 03:42 kotlinAdder.jar
drwxrwxr-x  3 thufir thufir   4096 Nov  5 03:42 META-INF/
drwxrwxr-x  3 thufir thufir   4096 Nov  5 03:42 net/
drwxrwxr-x  4 thufir thufir   4096 Nov  5 03:42 org/
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ nano META-INF/MANIFEST.MF 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ cat META-INF/MANIFEST.MF 
Manifest-Version: 1.0
Main-Class: net.bounceme.dur.kotlin.App

thufir@dur:~/NetBeansProjects/kotlin/build/libs$ 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ nano META-INF/MANIFEST.MF 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ cat META-INF/MANIFEST.MF 
Manifest-Version: 1.0
Main-Class: demo.MainKt
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ 
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ java -jar kotlinAdder.jar 
Hello, world!
thufir@dur:~/NetBeansProjects/kotlin/build/libs$ 

各种各样的成功。它按照预期运行了Kotlin课程。

项目:

.
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
    ├── main
    │   ├── java
    │   │   └── net
    │   │       └── bounceme
    │   │           └── dur
    │   │               └── kotlin
    │   │                   └── App.java
    │   └── kotlin
    │       └── demo
    │           ├── example.kt
    │           └── main.kt
    └── test
        └── java

13 directories, 9 files

构建文件:

plugins {
    id 'com.gradle.build-scan' version '1.8' 
    //   id 'java'
    id 'application'
    id "org.jetbrains.kotlin.jvm" version "1.1.51"
    id 'com.github.johnrengelman.shadow' version '2.0.1'
}

buildScan {
    licenseAgreementUrl = 'https://gradle.com/terms-of-service'
    licenseAgree = 'yes'
    //publishAlways()
}

configurations {
    provided
}

shadowJar {
    baseName = 'kotlinAdder'
    classifier = null
    version = null
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

//mainClassName = 'net.bounceme.dur.kotlin.App'
mainClassName = 'demo.MainKt'

repositories {
    jcenter()
}

configurations {
    provided
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.51"
    compile 'com.google.firebase:firebase-auth:11.4.2'

} 

如何告诉gradle继续使用shadowJar,但要手动编辑MANIFEST.MF,将Main-Class: demo.MainKt明确设置为入口点。

另外,当我在build.gradle文件中明确设置输入点时,Java代码runs by default 甚至

0 个答案:

没有答案