【问题标题】:Run mvn spring-boot:run from parent module?从父模块运行 mvn spring-boot:run?
【发布时间】:2017-04-26 19:23:48
【问题描述】:

我有一个这样的多模块 maven 项目:

我的父母
--我的域
--我的服务
--my-app

我想直接从父模块运行mvn spring-boot:run 命令无需先进入“my-app”目录

我认为这与 spring-boot-maven-plugin 的配置有关,但我似乎无法正确理解。

我尝试了以下方法:

  1. 使用spring-boot-starter-parent 和其他默认配置,spring-boot-maven-plugin 包含在 my-app 的插件部分。
    从父级运行 mvn spring-boot:run 会导致:
    Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:run (default-cli) on project my-parent: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1] in the parent module

  2. 请勿使用spring-boot-starter-parent
    在 depManagement 中定义 spring-boot-dependencies,如 elewhere 所述。
    my-parent 的 pluginManagement 部分定义 spring-boot-maven-plugin 并将插件包含在 my-app 模块的 plugins 部分中。
    从父级运行 mvn spring-boot:run 会导致与 #1 相同的错误:
    未能在项目 my-parent 上执行目标 org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:run (default-cli):找不到合适的主类,请添加“主类”属性 -> [帮助 1]

  3. 请勿使用spring-boot-starter-parent
    在 depManagement 中定义 spring-boot-dependencies,如 elewhere 所述。
    my-app 的插件部分定义 spring-boot-maven-plugin
    从父级运行 mvn spring-boot:run 会导致:
    No plugin found for prefix 'spring-boot' in the current project and in the plugin groups

在上述所有情况下,从 my-app 目录运行 mvn spring-boot:run 都可以正常工作。

我认为应该有一种方法可以使这项工作。在传统的非 Boot Spring 项目中,配置 tomcat7 插件相当简单,这样我就可以从父级运行 mvn tomcat7:run-war 并且 webapp 子模块将按预期启动

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    您可以通过在父 pom 中添加以下内容来做到这一点:

      <build>
        <plugins>
          <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
        </plugins>
      </build>
    

    在你的 在我的应用程序(Spring Boot 模块)pom 中:

     <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <fork>true</fork>
          <skip>false</skip>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    

    现在您可以在项目根目录中执行:

    mvn -pl my-app -am spring-boot:run
    

    其他参考资料:

    【讨论】:

    【解决方案2】:

    spring-boot maven 插件配置选项:

    skip: skips the execution of sprint-boot:run  [default: false]
    
    fork: Flag to indicate if the run processes should be forked [default: true]
    

    spring-boot maven plugin parameters

    maven 选项:

    -pl, --projects: Comma-delimited list of specified reactor projects to build instead of all projects. A project can be specified by [groupId]:artifactId or by its relative path   
    
    -am, --also-make: If project list is specified, also build projects required by the list
    

    maven CLI options

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-25
      • 2016-10-09
      • 2016-04-10
      • 2020-09-27
      相关资源
      最近更新 更多