【问题标题】:How to access only one class from different module in multi-module spring boot application gradle?如何在多模块spring boot应用程序gradle中只访问不同模块的一个类?
【发布时间】:2021-11-19 06:28:44
【问题描述】:

我的多模块 Spring Boot 应用程序中有 2 个模块(模块 A 和模块 B),使用 gradle 构建。

现在 Spring Boot 模块的 Main 类出现在模块 A 中。 现在我想在模块 B 中访问这个 Main 类。

在模块 B 中,我想编写集成测试用例和一个测试用例类,我想在 SpringBootTest 注释中提及Main 类。像这样的:

@SpringBootTest(classes = Main.class,
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class TestController {

}

但是在这里我找不到Main 类。我需要在模块 B 的 gradle 文件中进行哪些更改以支持此功能?

【问题讨论】:

    标签: spring-boot gradle integration-testing multi-module


    【解决方案1】:

    最好将您的项目拆分为模块。 您的 settings.gradle 和 build.gradle 应该如下所示:

    settings.gradle

    include 'moduleA'
    include 'moduleB'
    

    moduleB/build.gradle

    dependencies{
      implementation project(':moduleA')
    }
    

    更多信息:https://docs.gradle.org/current/userguide/multi_project_builds.html

    如果您真的只想将类作为源文件,那么这应该可以:

    sourceSets {
        main {
            java {
                srcDirs 'path/to/the/class'
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-08-17
      • 1970-01-01
      • 2022-11-11
      • 2019-03-26
      • 1970-01-01
      • 2021-06-12
      • 2023-03-19
      • 2020-12-29
      • 2017-04-26
      相关资源
      最近更新 更多