apache/maven · error · DuplicateParameterException

{parameterName} has been declared multiple times in mojo wit

Error message

{parameterName} has been declared multiple times in mojo with goal: {goal} (implementation: {implementation})

What it means

MojoDescriptor.addParameter rejects a Parameter that is already present (the internal list uses Parameter equality, effectively by name). Plugin descriptor assembly, whether from plugin.xml or extracted annotations, hits this when one mojo declares the same parameter name twice.

Source

Thrown at compat/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java:235

    /**
     * @param parameters the new list of parameters
     * @throws DuplicateParameterException if any
     */
    public void setParameters(List<Parameter> parameters) throws DuplicateParameterException {
        this.parameters.clear();
        for (Parameter parameter : parameters) {
            addParameter(parameter);
        }
    }

    /**
     * @param parameter add a new parameter
     * @throws DuplicateParameterException if any
     */
    public void addParameter(Parameter parameter) throws DuplicateParameterException {
        if (parameters.contains(parameter)) {
            throw new DuplicateParameterException(parameter.getName()
                    + " has been declared multiple times in mojo with goal: " + getGoal() + " (implementation: "
                    + getImplementation() + ")");
        }

        parameters.add(parameter);
    }

    /**
     * @return the list parameters as a Map (keyed by {@link Parameter#getName()}) that is built from
     * {@link #parameters} list on each call. In other words, the map returned is built on fly and is a copy.
     * Any change to this map is NOT reflected on list and other way around!
     */
    public Map<String, Parameter> getParameterMap() {
        LinkedHashMap<String, Parameter> parameterMap = new LinkedHashMap<>();

        for (Parameter pd : parameters) {
            parameterMap.put(pd.getName(), pd);
        }

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Remove or rename the duplicate <parameter> entry in plugin.xml
  2. Search the mojo source for two @Parameter members resolving to the same name (explicit name= or identical field names)
  3. Regenerate plugin.xml with current maven-plugin-tools instead of hand-merging
  4. When building descriptors programmatically, check descriptor.getParameterMap().containsKey(name) before addParameter

Example fix

<!-- before: plugin.xml declares the same parameter twice -->
<mojo>
  <goal>deploy</goal>
  <parameters>
    <parameter><name>target</name></parameter>
    <parameter><name>target</name></parameter>
  </parameters>
</mojo>

<!-- after: one entry per parameter name -->
<mojo>
  <goal>deploy</goal>
  <parameters>
    <parameter><name>target</name></parameter>
    <parameter><name>mode</name></parameter>
  </parameters>
</mojo>
Defensive patterns

Strategy: validation

Validate before calling

// Guard programmatic descriptor assembly
if (mojoDescriptor.getParameterMap().containsKey(parameter.getName())) {
    throw new IllegalArgumentException(
        "Duplicate parameter in plugin.xml: " + parameter.getName());
}
mojoDescriptor.addParameter(parameter);

Type guard

static boolean isDuplicateParameter(MojoDescriptor d, Parameter p) {
    return d.getParameterMap().containsKey(p.getName());
}

Prevention

When it happens

Trigger: plugin.xml with two <parameter> entries of the same name for one mojo; two @Parameter members whose configured names collide; programmatic descriptor building calling addParameter twice for the same name.

Common situations: Copy-pasted plugin.xml blocks; refactors that renamed a field but kept the old name via @Parameter(name=...); hand-merging descriptor fragments.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/6cc51cc877d6a736. Report an issue: GitHub.