3

I created a project with 3 modules:

enter image description here

In kazi-core, i have some entities and enumes and i want to use thoses in api module.

My kazi-core pom.xml:

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

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

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

I have one main class in kazi-core module:

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

my kazi-api pom.xml:

<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>${parent.version}</version>
    <packaging>jar</packaging>

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

    <properties>
        <org.mapstruct.version>1.2.0.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-jdk8</artifactId>
            <version>${org.mapstruct.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <verbose>true</verbose>
                    <annotationProcessorPaths>
                        <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>

My parent pom.xml:

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

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

    <modules>
        <module>build</module>
        <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>
</project>

i have a parent pom.xml where i defined all the starter dependencies.

by mvn clean install, a lot of symbol cannot find:

Error:(4,30) java: package com.kazi.core.entities does not exist
Error:(12,29) java: cannot find symbol
Error:(14,41) java: cannot find symbol
Error:(17,5) java: cannot find symbol

enter image description here

when i remove:

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

i don't have any compilation error. But i want to create a runnable jar.

3
  • As I see you're using Idea as IDE. After you add kazi-core to kazi-api a) did you update / reimport Maven project b) Is Maven auto import enabled? Commented Jun 9, 2020 at 18:33
  • Do you have that project on github or a like? Commented Jun 9, 2020 at 20:13
  • @zforgo when i remove the plugin in kazi-core, i don't have any compilation error. Please see my update Commented Jun 10, 2020 at 4:11

1 Answer 1

5

i moved the build tag in the parent pom.xml and added an execution tag to Main class in kazi-core module:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <mainClass>com.emo.core.Application</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

i added in kazi-api and kazi-service a build tag and skip the execution:

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

it worked fine.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.