[maven] 스프링 부트-부모 pom이 이미있을 때 부모 pom

이미 필요한 부모 POM이있는 프로젝트에 스프링 부트 부모 pom을 포함시키는 데 권장되는 특정 접근 방법이 있습니까?

조직의 부모로부터 확장해야하는 프로젝트에 권장하는 사항 (이것은 매우 일반적이며 대부분의 프로젝트는 피더 저장소에 따라 Maven Central에 게시됩니다). 대부분의 빌드 작업은 실행 가능한 JAR 작성 (예 : 임베디드 Tomcat / Jetty 실행)과 관련이 있습니다. 부모로부터 확장하지 않고 (구성 대 상속과 유사하게) 모든 종속성을 얻을 수 있도록 구조를 구성하는 방법이 있습니다. 그래도 빌드 물건을 얻을 수는 없습니다.

따라서 필요한 부모 POM 안에 모든 스프링 부트 부모 pom을 포함하거나 단순히 프로젝트 POM 파일 내에 POM 종속성을 갖는 것이 좋습니다.

다른 옵션?

티아,

스캇



답변

spring-boot-starter-parent를 “bom”처럼 사용하고 ( 이 기능을 지원하는 Spring 및 Jersey 기타 프로젝트 참조) scope = import를 사용하여 종속성 관리 섹션에만 포함시킬 수 있습니다. 실제 부모의 설정을 바꾸지 않고 사용 (즉, 종속성 관리)의 이점.

다른 두 가지 주요 기능은

  1. 재정의하려는 종속성 버전을 빠르게 설정하기위한 속성로드 정의
  2. 기본 구성으로 기본적으로 일부 플러그인을 구성하십시오 (주로 Spring Boot Maven 플러그인). 부모님을 사용한다면 수동으로해야 할 일입니다.

Spring Boot 문서에 제공된 예제 :

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.1.3.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>


답변

1.5.9.RELEASE로 2018-01-04 업데이트

https://www.surasint.com/spring-boot-with-no-parent-example/에 전체 코드와 실행 가능한 예제가 있습니다.

이것을 기본으로 필요합니다

   <dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${springframework.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

그러나 이것으로 충분하지 않으므로 spring-boot-maven-plugin의 목표를 명시 적으로 정의해야합니다 (Spring Boot를 부모로 사용하는 경우 명시 적으로 정의 할 필요가 없습니다)

    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${springframework.boot.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

그렇지 않으면 실행 가능한 jar 또는 war로 빌드 할 수 없습니다.

아직 JSP를 사용하는 경우 다음이 필요합니다.

<properties>
  <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>

그렇지 않으면이 오류 메시지가 나타납니다.

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project spring-boot-09: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executi
ng in update mode) -> [Help 1]

NO NO, “$ {}”대신 “@”가있는 Spring Boot에서 Maven 프로파일 및 리소스 필터를 사용하는 경우 여전히 충분하지 않습니다 (예 : https://www.surasint.com/spring-boot-maven -resource-filter / ). 그런 다음 이것을 명시 적으로 추가해야합니다.

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

그리고 이것은

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <delimiters>
                    <delimiter>@</delimiter>
                </delimiters>
                <useDefaultDelimiters>false</useDefaultDelimiters>
            </configuration>
        </plugin>

https://www.surasint.com/spring-boot-with-no-parent-example/ 링크의 예를 참조 하십시오 .


답변

Surasin Tancharoen의 답변에 따라 maven surefire 플러그인을 정의 할 수도 있습니다

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven-surefire-plugin.version}</version>
        </plugin>

페일 패스트 플러그인 포함

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>${maven-failsafe-plugin.version}</version>
        <executions>
            <execution>
                <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                </goals>
            </execution>
        </executions>
    </plugin>


답변