elharo commented on code in PR #829: URL: https://github.com/apache/maven-shade-plugin/pull/829#discussion_r3865064757
########## src/site/markdown/examples/module-info-merging.md.vm: ########## @@ -0,0 +1,200 @@ +--- +title: Merging Java Module Descriptors +author: + - The Apache Maven Team +date: 2026-07-30 +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +# Merging Java Module Descriptors + +By default, the plugin discards every root and versioned `module-info.class` from the inputs. This preserves the +historical behavior: an unmodified descriptor would describe the original artifact rather than the contents of the +shaded JAR. + +Modular projects can opt into descriptor merging: + +```xml +<project> + ... + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <moduleInfoMode>merge</moduleInfoMode> + <moduleInfo> + <publicBoundary>merge</publicBoundary> + <analysisJdkToolchain> + <version>21</version> + </analysisJdkToolchain> + </moduleInfo> + <relocations> + <relocation> + <pattern>com.example.internal</pattern> + <shadedPattern>com.example.shaded.internal</shadedPattern> + </relocation> + </relocations> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + ... +</project> +``` + +Merge mode models the shaded JAR as if the retained, relocated source files had been compiled together as one module. +The primary artifact remains authoritative for the module name, version, main class, and, by default, the public Review Comment: I don't like moving a direct negative, but no. Using both the original jar and the shaded jar at the same time is *exactly* why projects shade. They need to have both in the classpath, typically because some code need a fork or a different version and some code needs the original. Or maybe they need a very specific version and want to make sure the wrong version doesn't get added to the classpath. I suppose they use two different versions in this case but they still have the same module name unless this is changed. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
