Don't fork me!

Travis CI status: Build Status

1. Introduction

This repo demonstrates example of spring-boot parent custom module usage.

project
  │
  ├── application
  │   ├── pom.xml
  │   └── src...
  ├── library
  │   ├── pom.xml
  │   └── src...
  ├── parent
  │   └── pom.xml
  └── pom.xml
maven build
./mvnw
java -jar ./application/target/*.jar
bash ./application/target/*.jar

generated by generator-jvm yeoman generator (java-spring-boot)

2. Implementation

1. create root project folder
mkdir spring-boot-parent-example
touch pom.xml
root
  <groupId>com.github.daggerok</groupId>
  <artifactId>spring-boot-parent-example</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <modules>
    <module>parent</module>
    <module>library</module>
    <module>application</module>
  </modules>

  <build>
    <defaultGoal>clean package</defaultGoal>
  </build>
2. create spring-boot parent project holder by generating it from start.spring.io project: maven type: pom
cd spring-boot-parent-example/
mkdir parent
touch parent/pom.xml
parent
  <groupId>com.github.daggerok</groupId>
  <artifactId>parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <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>

    <defaultGoal>clean package</defaultGoal>
  </build>
3. / 4. create maven submodules with parent not spring-boot-parent, but previously create one: parent
mkdir library application
touch library/pom.xml application/pom.xml
library
  <artifactId>application</artifactId>
  <packaging>jar</packaging>

  <parent>
    <groupId>com.github.daggerok</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../parent</relativePath>
  </parent>

  <dependencies>
    <dependency>
      <groupId>com.github.daggerok</groupId>
      <artifactId>library</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>
application
  <artifactId>application</artifactId>
  <packaging>jar</packaging>

  <parent>
    <groupId>com.github.daggerok</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../parent</relativePath>
  </parent>

  <dependencies>
    <dependency>
      <groupId>com.github.daggerok</groupId>
      <artifactId>library</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>