Search code examples
javamavenspring-mvcwar

Maven war - 'packaging' with value 'war' is invalid. Aggregator projects require 'pom' as packaging


I have a maven project which previously worked with the following structure, except for the war packaging, build plugin and webapp/:

Project structure And the following parent pom.xml build cycle

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <warName>${project.artifactId}</warName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>install</id>
                        <phase>install</phase>
                        <goals>
                            <goal>sources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <finalName>ConcertLiveCheck</finalName>
</build>

but, whenever i attempt to compile my project as a war, i receive the following error

    'packaging' with value 'war' is invalid. Aggregator projects require 'pom' as packaging

Beforehand, i was compiling as pom, without the maven war plugin and every maven module was compiling correctly to it's target, and my project was running. But, since i intend to run my project on a web server, i am attempting to compile to a POM, to later on auto deploy to my web server.

Any tips on solving the issue?

Thank you,


Solution

  • Your project is a parent (aggregator) it contains child modules (a number of different projects).

    A parent has to have type of pom. If you want to add a war it will have to be a child module.

    In your parent you will have something like :

     <modules>
        <module>example-ear</module>
        <module>example-war</module>
      </modules>
    

    Then your war project will look like this :

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
    
      <parent>
        <groupId>com.greg</groupId>
        <artifactId>ear-example</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
    
      <artifactId>example-war</artifactId>
      <packaging>war</packaging>
    
      <name>com.greg</name>
      <url>http://maven.apache.org</url>
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
      <dependencies>
            ...
            ...
            ...
      </dependencies>
      <build>
           ...
           add all your war plugins here
           ...
      </build>
    </project>
    

    See https://maven.apache.org/guides/mini/guide-multiple-modules.html