6

I'm trying to test the overlay functionality of the maven-war-plugin. Basically I need to merge two war projects.

So I defined a war as dependency:

<dependency> 
  <groupId>my.group.id</groupId> 
  <artifactId>my-legacy-war-project</artifactId> 
  <version>${project.version}</version> 
  <type>war</type> 
</dependency>

And then configured the overlay:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <overlays>
      <overlay>
        <groupId>my.group.id</groupId>
        <artifactId>my-legacy-war-project</artifactId>
        <targetPath>legacy</targetPath>
      </overlay>
    </overlays>
  </configuration>
</plugin>

But Maven fails to build this project, complaining about this dependency:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:exploded (default) on project my-project: overlay [ id my.group.id:my-legacy-war-project] is not a dependency of the project. -> [Help 1]

The overlay is supposed to work with Maven 3.0.5? Why the build is complaining about a dependency that's declared?

4 Answers4

11

Not sure why, but using id instead of groupId and artifactId in the overlay worked:

  <configuration>
    <overlays>
      <overlay>
        <id>my-legacy-war-project</id>
        <targetPath>legacy</targetPath>
      </overlay>
    </overlays>
  </configuration>
  • Same here... Absolutely weird. – Lawrence Dec 22 '15 at 14:22
  • Perhaps this is relevant: http://stackoverflow.com/questions/12298178/maven-depend-on-assembled-zip, particularly this part: > For anyone else's benefit, what I was missing is that the of the dependency > has to match the of the assembly. – Jeremy K Dec 14 '16 at 21:39
3

I had the same error, but possibly for a different reason, since you are bringing in a war dependency. In my case, I had a war dependency as one overlay, and a jar dependency as another. The build complained about the jar dependency:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.4:war (default-war) on project overlay: overlay [ id com.mycompany:launcher] is not a dependency of the project.

I fixed the error by adding a <type>jar</type> element to my jar overlay. According to the overlay documentation, the default value for type is war, and so the build correctly complained that I did not have a war artifact named launcher.

Here's the working pom for my overlay project:

<project>

<artifactId>overlay</artifactId>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>com.mycompany</groupId>
        <artifactId>app</artifactId>
        <type>war</type>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.mycompany</groupId>
        <artifactId>launcher</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <overlays>
                        <overlay>
                            <groupId>com.mycompany</groupId>
                            <artifactId>app</artifactId>
                        </overlay>
                        <overlay>
                            <groupId>com.mycompany</groupId>
                            <artifactId>launcher</artifactId>
                            <type>jar</type>  <!-- THIS IS THE FIX -->
                        </overlay>
                    </overlays>
                </configuration>
        </plugin>
    </plugins>
</build>

chaserb
  • 1,340
  • 1
  • 14
  • 25
  • 1
    That fixed the exact same issue for me, and the reason i think is because if no type is specified it assumes is a war type since is less common to use jars as overlays for war builds – AbelSurace Dec 18 '22 at 04:37
1

I had the same problem with maven-war-plugin version 2.2 and abuse of duplicate plugin declaration. After unifying them and using Sergio Michels suggestion, now it works fine using version 2.3 of maven-war-plugin.

Before changing:

<plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <dependentWarExcludes>'**/jdbc.properties,**/hibernate.cfg.xml,**/sql-map-config.xml,**/web.xml,WEB-INF/classes/META-INF/**'</dependentWarExcludes>
            </configuration>
</plugin>          
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <warName>my-snapshot</warName>
                <overlay>
                    <overlay>
                    <id>my-webapp-common</id>
                    <groupId>xyz.mycompany</groupId>
                    <artifactId>my-webapp-common</artifactId>
                    </overlay>
                </overlays>
            </configuration>
</plugin>

After applying changes:

           <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <warName>my-snapshot</warName>
                <overlays>
                <overlay>
                    <overlay>
                        <id>my-webapp-common</id>
                        <targetPath>legacy</targetPath>
                    </overlay>
                </overlays>
                <dependentWarExcludes>'**/jdbc.properties,**/hibernate.cfg.xml,**/sql-map-config.xml,**/web.xml,WEB-INF/classes/META-INF/**'</dependentWarExcludes>
          </configuration>
        </plugin>
Community
  • 1
  • 1
Kayvan Tehrani
  • 3,070
  • 2
  • 32
  • 46
1

Expanding on the other answers. The problem is to get overlay to use the same id as dependency.

Using $ mvn dependency:list can show you the ID you need. For example:

[INFO] +- com.foo.bar.v2:api:jar:1.0:system 
[INFO] \- com.foo.bar.v2:main-server:war:1.0:system 
[INFO] \- com.foo.bar.v2:second-server:war:classes:1.0:system

Shows one jar and one war. Note: :jar vs :war is entirely controlled by whether you used <type>war</type> in your dependency. Similarly, :classes (or empty) is entirely controlled by whether you used <classifier>classes</classifier> in your dependency.

You need to get this in alignment with <overlay>. For com.foo.bar.v2:main-server:war:1.0:system listed above, this would be the overlay entry:

<overlay>
    <id>com.foo.bar.v2:main-server:war:1.0</id>
    <groupId>com.foo.bar.v2</groupId>
    <artifactId>main-server</artifactId>
</overlay>

For com.foo.bar.v2:second-server:war:classes:1.0:system, this would be the correct entry:

<overlay>
    <id>com.foo.bar.v2:main-server:war:1.0</id>
    <groupId>com.foo.bar.v2</groupId>
    <artifactId>main-server</artifactId>
    <classifier>classes</classifier>
</overlay>
Hamy
  • 20,662
  • 15
  • 74
  • 102