Solving Unable to load the mojo ‘war’ in the plugin

If you are working with Maven and encounter the error message “Unable to load the mojo ‘war’ in the plugin ‘org.apache.maven.plugins:maven-war-plugin‘ due to an API incompatibility,” don’t worry. This error typically occurs when there is an issue with the compatibility of the Maven War Plugin. Fortunately, it can be easily resolved by updating the Maven War Plugin to the latest version. In this article, we will guide you through the steps to fix this error and get your Maven build running smoothly again.

Prerequisites

  • Basic knowledge of Maven and its plugins.
  • Familiarity with the command-line interface (CLI).

Problem Description

When executing the mvn clean install or mvn package command, you encounter the following error message:

Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.4:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.4' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null

Solution Steps

To resolve this error, you need to update the Maven War Plugin to the latest version. Follow the steps below:

  1. Open your project’s pom.xml file in a text editor or integrated development environment (IDE) of your choice.
  2. Locate the <build> section within the pom.xml file. If it doesn’t exist, create one as a child element of the <project> element.
  3. Inside the <build> section, find the <plugins> element. If it doesn’t exist, create it as a child element of the <build> element.
  4. Within the <plugins> section, locate the following entry for the Maven War Plugin:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
</plugin>

Update the version of the Maven War Plugin to the latest stable version. You can find the latest version by visiting the Maven War Plugin’s official documentation or by checking the Maven Central Repository.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.2</version>
</plugin>

Save the pom.xml file.

Open a command-line interface (CLI) and navigate to the root directory of your project, where the pom.xml file is located.

Run the Maven build command to test if the error has been resolved:

mvn clean install

The build should now execute without encountering the previous error.

Congratulations! You have successfully resolved the “Unable to load the mojo ‘war’ in the plugin ‘org.apache.maven.plugins:maven-war-plugin'” error. By updating the Maven War Plugin to the latest version, you ensure compatibility and allow your Maven build to proceed smoothly.

Conclusion

In this article, we addressed the error message “Unable to load the mojo ‘war’ in the plugin ‘org.apache.maven.plugins:maven-war-plugin’ due to an API incompatibility” encountered during a Maven build. We provided a step-by-step solution by updating the Maven War Plugin to the latest version. By following these steps, you