본문 바로가기

JAVA/Spring Boot

메이븐 멀티 프로젝트 구성

반응형

 

예제에서 참고한 메이븐 멀티 프로젝트 구성

taco-cloud-parent pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>sia</groupId>
      <artifactId>taco-cloud-parent</artifactId>
      <version>0.0.7-SNAPSHOT</version>
    <packaging>pom</packaging>

    <parent>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-parent</artifactId>
          <version>2.0.4.RELEASE</version>
          <relativePath/>
      </parent>

    <properties>
      <maven.compiler.source>1.8</maven.compiler.source>
      <maven.compiler.target>1.8</maven.compiler.target>
      <tacocloud.version>${project.version}</tacocloud.version>
    </properties>

    <modules>
      <module>tacos</module>
      <module>tacocloud-api</module>
      <module>tacocloud-data</module>
      <module>tacocloud-domain</module>
      <module>tacocloud-restclient</module>
      <module>tacocloud-security</module>
      <module>tacocloud-web</module>
      <module>tacocloud-ui</module>
    </modules>

</project>
  • 모듈 구성

tacos pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>taco-cloud</artifactId>
    <packaging>jar</packaging>

    <name>taco-cloud</name>
    <description>Taco Cloud Example</description>

    <parent>
        <groupId>sia</groupId>
        <artifactId>taco-cloud-parent</artifactId>
        <version>0.0.7-SNAPSHOT</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- TacoCloud dependencies -->
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-data</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-domain</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-security</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-api</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-ui</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>

        <!-- Run against embedded H2 database by default -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- Actuator and DevTools...just because -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>htmlunit-driver</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.23.1-GA</version>
        </dependency>

    </dependencies>

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

</project>
  • 환경설정 모듈
  • application.yml
  • Application @SpringBootApplication 설정

tacocloud-api pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>tacocloud-api</artifactId>
    <packaging>jar</packaging>

    <name>tacocloud-api</name>
    <description>Taco Cloud API</description>

    <parent>
        <groupId>sia</groupId>
        <artifactId>taco-cloud-parent</artifactId>
        <version>0.0.7-SNAPSHOT</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- TacoCloud dependencies -->
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-data</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-domain</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-security</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>

        <!-- Necessary Boot starters -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>

        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>
  • api 모듈
  • web.api 패키지로 @RestController

tacocloud-data pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>tacocloud-data</artifactId>
    <packaging>jar</packaging>

    <name>tacocloud-data</name>
    <description>Taco Cloud Data</description>

    <parent>
        <groupId>sia</groupId>
      <artifactId>taco-cloud-parent</artifactId>
        <version>0.0.7-SNAPSHOT</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- TacoCloud dependencies -->
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-domain</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>

        <!-- Necessary Boot starters -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>
  • data 패키지
  • Repository

tacocloud-domain pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>tacocloud-domain</artifactId>
    <packaging>jar</packaging>

    <name>tacocloud-domain</name>
    <description>Taco Cloud Domain</description>

    <parent>
        <groupId>sia</groupId>
      <artifactId>taco-cloud-parent</artifactId>
        <version>0.0.7-SNAPSHOT</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- Necessary Boot starters -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>

        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- H2 - TBD if this is strictly necessary except for testing -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>
  • @Entity 구성

tacocloud-security pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>tacocloud-security</artifactId>
    <packaging>jar</packaging>

    <name>tacocloud-security</name>
    <description>Taco Cloud Security</description>

    <parent>
        <groupId>sia</groupId>
      <artifactId>taco-cloud-parent</artifactId>
        <version>0.0.7-SNAPSHOT</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- TacoCloud dependencies -->
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-data</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-domain</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>

        <!-- Necessary Boot starters -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>
  • 시큐리티 모듈
  • @Controller 계정 등록용
  • @EnableWebSecurity 시큐리티 설정
  • @Service
  • @Data 계정등록 Form Data

tacocloud-ui pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>tacocloud-ui</artifactId>
    <packaging>jar</packaging>

    <parent>
        <groupId>sia</groupId>
      <artifactId>taco-cloud-parent</artifactId>
        <version>0.0.7-SNAPSHOT</version>
    </parent>

    <name>tacocloud-ui</name>
    <description>Taco Cloud UI</description>

  <properties>
      <node.version>v6.9.1</node.version>
      <yarn.version>v0.24.6</yarn.version>
      <frontend-maven-plugin.version>1.4</frontend-maven-plugin.version>
      <environment>dev</environment>
  </properties>

  <build>
    <resources>
      <resource>
        <directory>dist</directory>
        <includes>
          <include>**/*</include>
        </includes>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>dist</directory>
              <includes>
                <include>*</include>
              </includes>
            </fileset>
          </filesets>
        </configuration>
      </plugin>

      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>${frontend-maven-plugin.version}</version>
        <executions>
          <execution>
            <id>install node and npm</id>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
            <configuration>
              <nodeVersion>${node.version}</nodeVersion>
              <npmVersion>${npm.version}</npmVersion>
            </configuration>
          </execution>
          <execution>
            <id>npm install</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>install</arguments>
            </configuration>
          </execution>
          <execution>
            <id>build</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run-script build</arguments>
            </configuration>
            <phase>generate-resources</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <configuration>
          <outputDirectory> ${project.build.outputDirectory}\static</outputDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
  • UI 모듈
  • node 구성
  • angular
  • build plugins 설정

tacocloud-web pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>tacocloud-web</artifactId>
    <packaging>jar</packaging>

    <name>tacocloud-web</name>
    <description>Taco Cloud Web</description>

    <parent>
        <groupId>sia</groupId>
      <artifactId>taco-cloud-parent</artifactId>
        <version>0.0.7-SNAPSHOT</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- TacoCloud dependencies -->
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-data</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-domain</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>

        <!-- Necessary Boot starters -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Misc -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>mustachejs</artifactId>
            <version>2.2.1</version>
        </dependency>
        <dependency>
            <groupId>nz.net.ultraq.thymeleaf</groupId>
            <artifactId>thymeleaf-layout-dialect</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.23.1-GA</version>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-java</artifactId>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>htmlunit-driver</artifactId>
          <scope>test</scope>
        </dependency>

        <!-- For the sake of the configuration properties class -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

</project>
  • web 모듈
  • @Controller
  • @Configuration webConfig
  • static
  • templates
  • META-INF

tacocloud-restclient pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>tacocloud-restclient</artifactId>
    <packaging>jar</packaging>

    <name>tacocloud-restclient</name>
    <description>Taco Cloud REST client</description>

    <parent>
        <groupId>sia</groupId>
        <artifactId>taco-cloud-parent</artifactId>
        <version>0.0.7-SNAPSHOT</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- TacoCloud dependencies -->
        <dependency>
            <groupId>sia</groupId>
            <artifactId>tacocloud-domain</artifactId>
            <version>${tacocloud.version}</version>
        </dependency>

        <!-- Necessary Boot starters -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Misc -->
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
  • restclient 모듈
  • 별도의 실행환경
  • Applicatioin @SpringBootConfiguration
  • @Service restClient 서비스 RestTemplate, Traverson 사용
  • application.yml web-application-type: none 설정

 

출처 - 스프링 인 액션 5판

저자 - 크레이그 윌즈 / 역자 - 심재철

반응형

'JAVA > Spring Boot' 카테고리의 다른 글

스프링 부트 기본-#1  (0) 2020.10.15
Spring MyBatis사용 및 설정  (1) 2020.10.13
Spring Data JPA 사용 및 설정  (0) 2020.08.22
REST API  (0) 2020.08.21
스프링 부트 기본설정  (0) 2020.08.20