[ 
https://issues.apache.org/jira/browse/CXF-9288?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18154740#comment-18154740
 ] 

Freeman Yue Fang commented on CXF-9288:
---------------------------------------

Thanks [~marco93], and thanks for the quick PR.

On the scopes: what matters is whether the generated code can compile against 
the classes the episode points to, i.e. whether the dependency is on the 
compile classpath. That is compile, provided (and system), but not runtime. I 
checked it with the IT project of the PR:

* lib with scope runtime: its episode is used, so Foo is not generated, and the 
app then fails to compile ("package acme.lib does not exist"), since runtime 
dependencies are not on the compile classpath.
* lib with scope provided: the episode is ignored and Foo is generated again, 
although the generated code would compile against the provided classes. 
Provided is a common case for shared model classes supplied by the container 
(app server module, OSGi bundle, parent classloader).

So I'd suggest using the compile classpath scopes (compile, provided, system) 
rather than compile + runtime. I've left a few other comments on the PR 
(reactor builds before package, where the dependency is target/classes rather 
than a jar, and the javadoc saying "direct" while transitive dependencies are 
included).

Freeman


> Add automatic discovery of JAXB episode files from Maven dependencies 
> (useDependenciesAsEpisodes)
> -------------------------------------------------------------------------------------------------
>
>                 Key: CXF-9288
>                 URL: https://issues.apache.org/jira/browse/CXF-9288
>             Project: CXF
>          Issue Type: Improvement
>            Reporter: Marco Semiao
>            Priority: Major
>             Fix For: 4.3.0
>
>
> h3. Context / Problem
> In multi-module architectures where XSD schemas are shared across several 
> projects, common JAXB classes are typically generated once in a dedicated 
> Maven module (packaging a JAXB episode file) and imported as a dependency in 
> downstream modules.
> Currently, when running {{wsdl2java}} via {{cxf-codegen-plugin}}, preventing 
> the regeneration of these already-compiled classes requires manually 
> declaring each episode file in the plugin configuration (via 
> {{<bindingFiles>}} or {{<extraargs>}}), which becomes verbose and error-prone 
> as the number of shared dependencies grows.
> h3. Proposed Feature
> Add an opt-in configuration parameter {{<useDependenciesAsEpisodes>}} 
> (boolean, {{false}} by default to preserve backward compatibility), inspired 
> by {{org.codehaus.mojo:jaxb2-maven-plugin}} (since version 4.1.1) and 
> {{jaxb-tools}}.
> When {{<useDependenciesAsEpisodes>true</useDependenciesAsEpisodes>}} is 
> enabled:
> # The plugin scans direct Maven project dependencies in {{compile}} and 
> {{runtime}} scopes (optionally paired with 
> {{<includeTransitiveEpisodes>false</includeTransitiveEpisodes>}}).
> # For each dependency JAR, it looks for a JAXB episode resource following 
> standard conventions:
> #* {{META-INF/sun-jaxb.episode}}
> #* {{META-INF/JAXB/*.xjb}}
> # Discovered episode files are extracted (e.g., under 
> {{${project.build.directory}/cxf-episodes/}}) and automatically passed as 
> external binding files to XJC during {{wsdl2java}} execution.
> h3. Example Configuration
> {code:xml}
> <plugin>
>     <groupId>org.apache.cxf</groupId>
>     <artifactId>cxf-codegen-plugin</artifactId>
>     <version>${cxf.version}</version>
>     <configuration>
>         <useDependenciesAsEpisodes>true</useDependenciesAsEpisodes>
>     </configuration>
>     <executions>
>         <execution>
>             <id>generate-sources</id>
>             <phase>generate-sources</phase>
>             <goals>
>                 <goal>wsdl2java</goal>
>             </goals>
>         </execution>
>     </executions>
> </plugin>
> {code}
> h3. Expected Benefits
> * Greatly simplifies Maven configuration in projects sharing common XSD data 
> models.
> * Avoids duplicate generated classes and classpath conflicts.
> * Aligns {{cxf-codegen-plugin}} with standard episode handling in other Maven 
> JAXB plugins.
> h3. Contribution Offer
> Before starting implementation, I would like to check if the community and 
> maintainers are interested in adding this feature to {{cxf-codegen-plugin}}. 
> If there is interest and agreement on the approach, I would be happy to 
> implement it and submit a Pull Request.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to