1

如何明确告诉shadowJar使用 Kotlin 文件作为结果的入口点uberJarJAR(或者,你喜欢胖。)

笨拙地编辑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明确设置为入口点。

否则,即使我在文件中明确设置了上述入口点,Java 代码也会默认运行build.gradle

4

0 回答 0