【问题标题】:Kotlin (Maven) - executable JAR without source filesKotlin (Maven) - 没有源文件的可执行 JAR
【发布时间】:2018-06-08 10:15:33
【问题描述】:


我想用 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 一起打包。我如何做到这一点?

【问题讨论】:

    标签: maven jar kotlin executable-jar resource-files


    【解决方案1】:

    尝试完全按照here 的描述在&lt;configuration&gt; 之外定义源集

    【讨论】:

      猜你喜欢
      • 2020-05-20
      • 2013-01-12
      • 1970-01-01
      • 2013-02-15
      • 2019-09-05
      • 2014-11-14
      • 2014-11-06
      • 1970-01-01
      • 2014-05-21
      相关资源
      最近更新 更多