Kotlin(Maven) - 没有源文件的可执行JAR
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kotlin(Maven) - 没有源文件的可执行JAR相关的知识,希望对你有一定的参考价值。
我想用maven创建一个可执行的kotlin jar文件。但不知何故,kotlin源文件都是用jar包装的。我配置了kotlin插件和maven组件插件来创建一个独立的jar。以下是我的pom的依赖项和插件:
<properties>
<project.basedir>.</project.basedir>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<kotlin.version>1.2.0</kotlin.version>
<kotlin.coroutines.version>0.20</kotlin.coroutines.version>
<main.class>server.RunKt</main.class>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- Kryonet dependencies -->
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryonet</artifactId>
<version>2.22.0-RC1</version>
</dependency>
<!-- RxJava dependencies -->
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.1.7</version>
</dependency>
<!-- Kotlin dependencies -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jre8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>${kotlin.coroutines.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
</sourceDirs>
<experimentalCoroutines>enable</experimentalCoroutines>
</configuration>
<executions>
<execution>
<id>compile</id>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals> <goal>single</goal> </goals>
<configuration>
<archive>
<manifest>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
jar运行正常,但我只是不希望kotlin源文件与jar一起打包。我如何实现这一目标?
答案
尝试在here之外定义与<configuration>
描述完全相同的源集
以上是关于Kotlin(Maven) - 没有源文件的可执行JAR的主要内容,如果未能解决你的问题,请参考以下文章
运行maven-assembly创建的可执行jar:错误:无法找到或加载主类