简体   繁体   中英

Build War with multi module project

I have a multi module maven project with three different modules Module-Data, Module-Domain, Module-Web. All three projects are spring boot projects, however Module-Web is the web component of the project that handles everything web oriented which I want to build a war file for. I have a parent project with the following pom file which contains no code.

<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>com.somename</groupId>
<artifactId>My-Project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
    <module>module-data</module>
    <module>module-domain</module>
    <module>modele-web</module>
</modules>

Module-Domain depends on Module-Data and Module-Web depends on both Module-Data and Module-Domain. The problem I'm having is that when I try to build the project using maven it fails when building the Module-Domain with the following erros:

package com.somename.data.model does not exist // class file with this error

Module-Domain class files that imports from the Module-Data project fails with this error. I suspect this is because maven is not adding the Module-Data jar to the Module-Domain when building although its referenced in its pom file. How can I solve this problem and generate a war file with all dependencies?

Module-Domain pom.xml:

    <dependency>
        <groupId>com.somename.data</groupId>
        <artifactId>module-data</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>

Module-Web pom.xml

   <dependency>
        <groupId>com.somename.data</groupId>
        <artifactId>module-data</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.somename.domain</groupId>
        <artifactId>module-domain</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

This is a simple straight-forward approach that you are using. Should not cause a problem.

Module-Domain pom.xml:

<parent>
    <groupId>com.somename</groupId>
    <artifactId>My-Project</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
    <dependency>
        <groupId>com.somename.data</groupId>
        <artifactId>module-data</artifactId>
        <version>0.0.1-SNAPSHOT</version> <!-- Make sure this version is correct -->
    </dependency>
</dependencies>

Module-Web pom.xml:

<parent>
    <groupId>com.somename</groupId>
    <artifactId>My-Project</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
    <dependency>
        <groupId>com.somename.domain</groupId>
        <artifactId>module-domain</artifactId> <!-- pulls "module-data" as well : transitive dependency -->
        <version>0.0.1-SNAPSHOT</version> <!-- Make sure this version is correct -->
    </dependency>
</dependencies>

Do maven clean compile on the parent project that would build all the modules.

If you still see any compilation issues, you would need fix the source code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM