apache/maven · error · PluginConfigurationException
Unable to inject field '${resolution.getField()}' annotated
Error message
Unable to inject field '${resolution.getField()}' annotated with @Dependencies What it means
The dependency result was computed, but the reflective Field.set on the @Dependencies-annotated field threw IllegalAccessException: the write was denied. setAccessible(true) was already called, so the usual culprits are a final field (modern JDKs refuse reflective writes to final fields) or module/SecurityManager restrictions blocking deep reflection into the plugin's classes.
Source
Thrown at impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java:672
DependencyResolverResult res = sessionV4
.getService(DependencyResolver.class)
.collect(sessionV4, project, PathScope.MAIN_RUNTIME);
if (field.getType() == DependencyResolverResult.class) {
result = res;
} else if (field.getType() == Node.class) {
result = res.getRoot();
}
}
if (result == null) {
throw new PluginConfigurationException(
pluginDescriptor,
"Unable to inject field '" + resolution.getField()
+ "' annotated with @Dependencies. Unsupported type " + field.getGenericType());
}
try {
field.set(mojo, result);
} catch (IllegalAccessException e) {
throw new PluginConfigurationException(
pluginDescriptor,
"Unable to inject field '" + resolution.getField() + "' annotated with @Dependencies",
e);
}
}
return mojo;
}
private <T> T loadV3Mojo(
Class<T> mojoInterface,
MavenSession session,
MojoExecution mojoExecution,
MojoDescriptor mojoDescriptor,
PluginDescriptor pluginDescriptor,
ClassRealm pluginRealm)
throws PluginContainerException, PluginConfigurationException {
T mojo;View on GitHub (pinned to e4093d4e12)
Solutions
- Remove the final modifier from the annotated field.
- Ensure plugin classes run from the classpath (or a module that opens its packages) so deep reflection is permitted.
- Disable any SecurityManager configuration that vetoes reflective writes during the build.
Example fix
// before @Dependencies private final Node node; // after @Dependencies private Node node;
Defensive patterns
Strategy: validation
Validate before calling
for (Field f : MyMojo.class.getDeclaredFields()) {
if (f.isAnnotationPresent(Dependencies.class)
&& (Modifier.isFinal(f.getModifiers()) || Modifier.isStatic(f.getModifiers()))) {
throw new IllegalStateException("@Dependencies field must be a non-final instance field: " + f);
}
} Try / catch
try {
mojo = pluginManager.getConfiguredMojo(mojoInterface, session, mojoExecution);
} catch (PluginConfigurationException e) {
if (e.getCause() instanceof IllegalAccessException) {
// reflective write denied: check final/static modifiers and module openness, do not retry
}
throw e;
} Prevention
- Never mark annotation-injected fields final or static in Maven plugins
- Ship a reflection sanity test in every plugin build
- Run plugin builds on the classpath (or open the plugin package) so deep reflection is permitted
When it happens
Trigger: The annotated field is declared final; the mojo classes are loaded under strong encapsulation (non-opened module path) or a SecurityManager vetoes the reflective write during the build.
Common situations: Maven-4 plugin authors marking injected fields final out of habit; restrictive JPMS or SecurityManager setups in the build JVM.
Related errors
- Error evaluating plugin parameter expression: ${expression}
- Failed to interpolate field: " + field + " on class: " + cls
- The token '%s' at position '%d' refers to a java.util.Map, b
- The token '%s' at position '%d' refers to a java.util.List o
- Cannot find default setter in {}
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/af97c693cb29f042.
Report an issue: GitHub.