You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow package-private @Parameter fields in Maven 4 API plugins #13459
In Maven 3, plugin parameters annotated with @Parameter on complex objects (nested configuration classes like <archive>) are injected by Plexus's EnhancedComponentConfigurator via reflection. This configurator requires either public fields or public setters on the target class, because it runs in a different classloader/module and cannot access package-private members without setAccessible(true).
This forces plugin authors to either expose public fields (which violates typical checkstyle VisibilityModifier rules) or write boilerplate getters/setters with no real API value.
Context
While refactoring maven-jar-plugin to remove its maven-archiver dependency (PR apache/maven-jar-plugin#618), we introduced a local ArchiveConfiguration class holding plugin config. Martin Kanters suggested making inner classes package-private with no getters/setters — a reasonable design for an implementation-internal config class. However, this is currently not feasible because EnhancedComponentConfigurator cannot inject into package-private fields.
Proposal
For Maven 4 API plugins (those depending on maven-api-plugin / using the new @Mojo from org.apache.maven.api.plugin.annotations), the mojo parameter configurator should support injecting into package-private fields — either by:
Calling field.setAccessible(true) before reflective access (already done for private fields in some configurators), or
Providing a dedicated, type-safe parameter binding mechanism that doesn't rely on reflection visibility rules.
This would allow Maven 4 API plugins to write clean, encapsulated config classes without public boilerplate:
// Current (forced by Plexus configurator):publicclassArchiveConfiguration {
privatebooleancompress = true;
publicbooleanisCompress() { returncompress; }
publicvoidsetCompress(booleancompress) { this.compress = compress; }
// ... 15 more getters/setters
}
// Desired (package-private, no boilerplate):classArchiveConfiguration {
booleancompress = true;
// used directly within the plugin package
}
In Maven 3, plugin parameters annotated with @parameter on complex objects (nested configuration classes like ) are injected by Plexus's EnhancedComponentConfigurator via reflection. This configurator requires either public fields or public setters on the target class, because it runs in a different classloader/module and cannot access package-private members without setAccessible(true).
PR #13470 fixes this by overriding the instantiateObject() call site in EnhancedConfigurationConverter.fromConfiguration() with a local instantiate() method that uses getDeclaredConstructor() + setAccessible(true) — symmetric with how EnhancedCompositeBeanHelper.setFieldValue() already handles non-public fields.
Activity
slawekjaranowski commentedon Oct 13, 2026
Is it true?
I see https://github.com/apache/maven-jar-plugin/blob/maven-jar-plugin-3.x/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java#L88-L89
without setters ....
gnodet commentedon Oct 13, 2026
PR #13470 fixes this by overriding the
instantiateObject()call site inEnhancedConfigurationConverter.fromConfiguration()with a localinstantiate()method that usesgetDeclaredConstructor() + setAccessible(true)— symmetric with howEnhancedCompositeBeanHelper.setFieldValue()already handles non-public fields.test: add regression test for apache#13459 (package-private construct…
[backport maven-4.0.x] Fix #13459: support package-private configurat…
Fix apache#13459: support package-private configuration classes in pl…