【问题标题】:How to use a Java main class on a Kotlin Spring Project?如何在 Kotlin Spring 项目中使用 Java 主类?
【发布时间】:2019-04-02 13:51:43
【问题描述】:

由于某些情况,我不得不将 Spring Boot 项目中的 Kotlin 主类更改为 Java。但是当我使用 Gradle 构建项目时,出现错误: Main class name has not been configured and it could not be resolved

我通过设置sourceSets.main.java.srcDirs = ['src'] 来解决构建问题,如Gradle - Could not find or load main class 中所述,但这会在本地搞砸一些事情(在 IntelliJ 中看不到包含整个源代码的 Kotlin 包)。 我怀疑有更好的方法来设置带有 Java 主类的 Kotlin 项目。

提前谢谢你

【问题讨论】:

    标签: java spring spring-boot gradle kotlin


    【解决方案1】:

    您是否尝试过使用mainClassName 属性?

    将此添加到您的 build.gradle 文件中:

        mainClassName = "com.my-package.my-another-package.MyMainClass"
    

    另外,请确保您应用了java 插件:

        apply plugin: 'java'
    

    【讨论】:

      猜你喜欢
      • 2020-04-06
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      • 2018-10-12
      • 2021-03-06
      • 2020-05-17
      • 1970-01-01
      • 2020-10-07
      相关资源
      最近更新 更多