apache/maven · error · ComponentConfigurationException

Cannot find default setter in {}

Error message

Cannot find default setter in {}

What it means

EnhancedConfigurationConverter instantiates the target bean when a configuration element's evaluated value does not fit the field type, then hands it to EnhancedCompositeBeanHelper.setDefault, which needs a default 'set' method: first a cached no-name lookup, then any single-parameter method literally named 'set'. If the bean's class has neither, configuration cannot proceed and ComponentConfigurationException 'Cannot find default setter in <beanType>' is thrown, naming the class.

Source

Thrown at impl/maven-core/src/main/java/org/apache/maven/configuration/internal/EnhancedCompositeBeanHelper.java:90

    /**
     * Calls the default "set" method on the bean; re-converts the configuration if necessary.
     */
    public void setDefault(Object bean, Object defaultValue, PlexusConfiguration configuration)
            throws ComponentConfigurationException {

        Class<?> beanType = bean.getClass();

        // Find the default "set" method
        MethodInfo setterInfo = findCachedMethod(beanType, "", null);
        if (setterInfo == null) {
            // Look for any method named "set" with one parameter
            Map<String, MethodInfo> classMethodCache = METHOD_CACHE.computeIfAbsent(beanType, this::buildMethodCache);
            setterInfo = classMethodCache.get("set");
        }

        if (setterInfo == null) {
            throw new ComponentConfigurationException(configuration, "Cannot find default setter in " + beanType);
        }

        Object value = defaultValue;
        TypeLiteral<?> paramType = TypeLiteral.get(setterInfo.parameterType);

        if (!paramType.getRawType().isInstance(value)) {
            if (configuration.getChildCount() > 0) {
                throw new ComponentConfigurationException(
                        "Basic element '" + configuration.getName() + "' must not contain child elements");
            }
            value = convertProperty(beanType, paramType.getRawType(), paramType.getType(), configuration);
        }

        if (value != null) {
            try {
                if (listener != null) {
                    listener.notifyFieldChangeUsingSetter("", value, bean);
                }

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Inspect the bean class named in the message in the version actually resolved (`mvn dependency:tree -Dincludes=...`) - does it expose a one-arg set method?
  2. Align plugin/tool version with the configuration style used (pin the version that matches).
  3. Rewrite the configuration to bind children to explicit setters/fields instead of the default composite form.
  4. If you own the bean class, add a `set(Value)` method accepting the element content.

Example fix

<!-- before: text value mapped onto a composite bean with no set() method -->
<extension>
  <myOption>legacy-value</myOption>
</extension>

<!-- after: bind to the explicit property setter the bean actually has -->
<extension>
  <myOptionValue>legacy-value</myOptionValue>
</extension>
Defensive patterns

Strategy: validation

Validate before calling

boolean hasDefaultSetter(Class<?> beanType) {
    for (Method m : beanType.getMethods()) {
        if ("set".equals(m.getName()) && m.getParameterCount() == 1) return true;
    }
    return false;
}
if (!hasDefaultSetter(beanType)) {
    throw new IllegalArgumentException("Bean " + beanType + " cannot take composite default value; fix configuration");
}

Prevention

When it happens

Trigger: A configuration element carrying a text value mapped onto a composite bean whose class exposes no one-arg set(...) method - typically after a dependency/plugin upgrade swapped the option class to one without the composite-friendly set method, or configuration written for a different plugin version.

Common situations: Version skew between a plugin and its API/option classes resolved from the dependency tree; hand-written component configuration assuming plexus composite conventions; upgrades of Maven itself tightening composite handling.

Related errors


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