You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2026/10/13 08:47:21 UTC

[I] Allow package-private @Parameter fields in Maven 4 API plugins [maven]

gnodet opened a new issue, #13459:
URL: https://github.com/apache/maven/issues/13459

   ## Summary
   
   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](https://github.com/apache/maven-jar-plugin/pull/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:
   
   1. Calling `field.setAccessible(true)` before reflective access (already done for private fields in some configurators), or
   2. 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:
   
   ```java
   // Current (forced by Plexus configurator):
   public class ArchiveConfiguration {
       private boolean compress = true;
       public boolean isCompress() { return compress; }
       public void setCompress(boolean compress) { this.compress = compress; }
       // ... 15 more getters/setters
   }
   
   // Desired (package-private, no boilerplate):
   class ArchiveConfiguration {
       boolean compress = true;
       // used directly within the plugin package
   }
   ```
   
   ## Target
   
   Maven 4.1.0


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Allow package-private @Parameter fields in Maven 4 API plugins [maven]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on issue #13459:
URL: https://github.com/apache/maven/issues/13459#issuecomment-6142019544

   > 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).
   
   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
   
   ```java
   @Parameter
   private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
   ```
   
   without setters ....


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Allow package-private @Parameter fields in Maven 4 API plugins [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on issue #13459:
URL: https://github.com/apache/maven/issues/13459#issuecomment-6144432286

   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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Allow package-private @Parameter fields in Maven 4 API plugins [maven]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet closed issue #13459: Allow package-private @Parameter fields in Maven 4 API plugins
URL: https://github.com/apache/maven/issues/13459


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org