1

Problem with Child module is that it inherent the dependency from parent pom. However parent pom marked that dependency with option tag.

This is the parent pom:

<?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>org.parent</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Parent</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</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>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <scope>compile</scope>
        <optional>true</optional>
    </dependency>
</dependencies>

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

<modules>
    <module>Child</module>
</modules>
</project>

This is Child pom:

<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>
<parent>
    <groupId>org.parent</groupId>
    <artifactId>Parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>org.child</groupId>
<artifactId>Child</artifactId>
</project>

Problem is when I starts child module, I can see tomcat initialization. I dont want to load tomcat for child module. How do I restrict tomcat dependency in child module? Do I need to define additional configuration to exclude it ? I already tried with exclusion tag but it didn't work.

T T
  • 170
  • 3
  • 9
  • I think you should not put dependencies into the parent pom if not all child projects use them. I do not whether it is possible at all to exclude such a dependency in a child module. – J Fabian Meier Sep 21 '18 at 12:08

2 Answers2

0

As you already mentioned you'll have to exclude those transitive Tomcat dependencies. Here's an example for doing so - not in a child module though but it should be similar:

How to exclude embeded Tomcat in Spring Boot application

0

This is not actually solution to this concern. However I got something that can do this trick to stop initializing tomcat for child modules. All that need is to disable it through

spring.main.web-application-type=none

More details can be found on this thread Spring boot enable/disable embedded tomcat with profile

T T
  • 170
  • 3
  • 9