简体   繁体   中英

Package multi module maven with nested modules

I have the following maven project structure

Project[pom.xml]                <type>pom</type>
-module 1[pom.xml]              <type>jar</type>
-module 2[pom.xml]              <type>pom</type>
     --SubModule1[pom.xml]      <type>jar</type>
     --SubModule2[pom.xml]      <type>jar</type>
     --SubModule3[pom.xml]      <type>war</type>
-module 3[pom.xml]              <type>ear</type>

my problem with the packaging, the output EAR file does not include module 2 when doing mvn clean install What I did in module 2 is to package as war. but then I could not the artifact to the ear file.

any ideas are appreciated.

I hope I am not congesting this question

below is the poms

Project 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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>project</groupId>
    <artifactId>project</artifactId>
    <version>1.0.0</version>

    <packaging>pom</packaging>
    <name>project</name>
    <description>Insert description for your project here.</description>

    <modules>
        <module>module1</module>
        <module>module2</module>
        <module>module3</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>module1</artifactId>
                <version>${project.version}</version>
                <type>jar</type>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>module2</artifactId>
                <version>${project.version}</version>
                <type>pom</type>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>wildfly-jakartaee8-with-tools</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <!--Configuration of the maven-compiler-plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${version.compiler.plugin}</version>
                <configuration>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>${version.wildfly.maven.plugin}</version>
                <inherited>true</inherited>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Module 2 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>project</groupId>
    <artifactId>project</artifactId>
    <version>1.0.0</version>
    <relativePath>../pom.xml</relativePath>
  </parent>
  <artifactId>module2</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <modules>
    <module>SubModule1</module>
    <module>SubModule2</module>
    <module>SubModule3</module>
  </modules>
  <properties>
    <!--suppress UnresolvedMavenProperty -->
    <context.root>/root</context.root>
    <!--suppress UnresolvedMavenProperty -->
    
  </properties>
  <dependencyManagement>
    <dependencies>

      <dependency>
        <groupId>project</groupId>
        <artifactId>SubModule1</artifactId>
        <version>1.0.0</version>
        <scope>provided</scope>
      </dependency>
      
      <dependency>
        <groupId>project</groupId>
        <artifactId>SubModule2</artifactId>
        <version>1.0.0</version>
        <scope>provided</scope>
      </dependency>
      
       <dependency>
        <groupId>project</groupId>
        <artifactId>SubModule3</artifactId>
        <version>1.0.0</version>
        <scope>provided</scope>
      </dependency>
      
    </dependencies>
  </dependencyManagement>
  
    <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
          <version>3.0.2</version>
        <configuration>
        
          <defaultLibBundleDir>lib</defaultLibBundleDir>
          <modules>
            <webModule>
              <groupId>project</groupId>
              <artifactId>SubModule3</artifactId>
              <contextRoot>${context.root}</contextRoot>
            </webModule>
          </modules>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

*** module3 EAR ***

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>project</groupId>
        <artifactId>project</artifactId>
        <version>1.0.0</version>
    </parent>
    <artifactId>module3</artifactId>
    <packaging>ear</packaging>

    <description>This is the EAR POM file</description>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>module1</artifactId>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>module2</artifactId>
            <type>pom</type>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.parent.artifactId}</finalName>
        <plugins>
            <!--EAR plugin: format of output file -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>${version.ear.plugin}</version>
                <configuration>
                    <version>8</version>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                    <modules>
                    </modules>
                    <outputFileNameMapping>@{artifactId}@@{dashClassifier?}@.@{extension}@</outputFileNameMapping>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <configuration>
                    <skip>false</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

The following declarations in the parent POM seem strange:

            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>module1</artifactId>
                <version>${project.version}</version>
                <type>jar</type>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>module2</artifactId>
                <version>${project.version}</version>
                <type>pom</type>
                <scope>provided</scope>
            </dependency>

They might cause the described problems.

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