2

I have a multi module project with maven and spring boot.

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

    <parent>
        <groupId>com.emo.kazi</groupId>
        <artifactId>kazi-parent</artifactId>
        <version>1.2-SNAPSHOT</version>
        <relativePath/>
    </parent>

    <artifactId>kazi</artifactId>
    <version>0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>kazi-core</module>
        <module>kazi-api</module>
        <module>kazi-service</module>
    </modules>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <build>
      <plugins>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>com.kazi.Application</mainClass>
            </configuration>
        </plugin>
      </plugins>
    </build>
</project>

Build failure by the first module with dependency to another module:

[INFO] kazi ............................................... SUCCESS [  2.186 s]
[INFO] kazi-core .......................................... SUCCESS [  4.640 s]
[INFO] kazi-api ........................................... FAILURE [  1.415 s]
[INFO] kazi-service ....................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.869 s
[INFO] Finished at: 2022-01-24T12:21:48+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project kazi-api: Compilation failure: Compilation failure: 
[ERROR] /../RegistrationRepository.java:[3,30] package com.kazi.core.entities does not exist
[ERROR] /../RegistrationRepository.java:[6,63] cannot find symbol
[ERROR]   symbol: class Registration

kazi-core is a module without dependency to another module, kazi-api has a dependency to kazi-core and kazi-service a dependency to kazi-api

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

    <parent>
        <groupId>com.emo.kazi</groupId>
        <artifactId>kazi</artifactId>
        <version>0.1-SNAPSHOT</version>
    </parent>

    <artifactId>kazi-core</artifactId>
    <version>${parent.version}</version>
    <packaging>jar</packaging>

    <name>kazi-core</name>
    <url>http://maven.apache.org</url>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.8.2</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-jaxb-annotations</artifactId>
        </dependency>
    </dependencies>

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

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

    <parent>
        <groupId>com.emo.kazi</groupId>
        <artifactId>kazi</artifactId>
        <version>0.1-SNAPSHOT</version>
    </parent>

    <artifactId>kazi-api</artifactId>
    <version>${project.parent.version}</version>
    <packaging>jar</packaging>

    <name>kazi-api</name>
    <url>http://maven.apache.org</url>

    <properties>
        <java.version>11</java.version>
        <org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.emo.kazi</groupId>
            <artifactId>kazi-core</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>${org.mapstruct.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <verbose>true</verbose>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.16</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok-mapstruct-binding</artifactId>
                            <version>0.2.0</version>
                        </path>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${org.mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <arg>-Amapstruct.suppressGeneratorTimestamp=true</arg>
                        <arg>-Amapstruct.defaultComponentModel=spring</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

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

    <parent>
        <groupId>com.emo.kazi</groupId>
        <artifactId>kazi</artifactId>
        <version>0.1-SNAPSHOT</version>
    </parent>

    <artifactId>kazi-service</artifactId>
    <version>${parent.version}</version>
    <packaging>jar</packaging>

    <name>kazi-service</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <dependency>
            <groupId>com.emo.kazi</groupId>
            <artifactId>kazi-api</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</project>

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

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

    <groupId>com.emo.kazi</groupId>
    <artifactId>kazi-parent</artifactId>
    <version>1.2-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- GrantedAuthority wird in kazi project bei Role verwendet -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.16</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-mapstruct-binding</artifactId>
            <version>0.2.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-plugin-releases</id>
            <url>https://repo.spring.io/plugins-release</url>
        </pluginRepository>
    </pluginRepositories>

</project>

When a skipped the spring-boot-maven-plugin it works fine:

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

My Application.class main class is in the core module.

How i have to use a spring-boot-maven-plugin in multi module project.

2 Answers 2

3

Use spring-boot-maven-plugin only in modules where you have main classes. Do not use the plugin in libs modules.

According to the current behavior: when you are using the plugin in the parent pom file, you automatically apply this plugin step for each nested module.

Sign up to request clarification or add additional context in comments.

1 Comment

i have removed the plugin from all pom.xml and left it only in core module with main class and got the same error.
1

I faced similar issue, it resolved for me.

  1. Keep the spring-boot-maven-plugin only in modules containing your main class. Remove it from all other modules.

  2. Update executable configuration in the spring-boot-maven-plugin like below.

     <plugin>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-maven-plugin</artifactId>
         <configuration>
             <executable>true</executable>
         </configuration>
     </plugin>
    

1 Comment

sorry but it didn't help ;-(

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.