Tarun4201 commented on code in PR #13277:
URL: https://github.com/apache/maven/pull/13277#discussion_r4116006372


##########
api/maven-api-cli/src/site/markdown/clapp.md:
##########
@@ -0,0 +1,129 @@
+<!---
+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.
+-->
+
+# Maven CLAPP (Command Line App) Guide
+
+Starting with Maven 4.1.0, Apache Maven provides native support for **CLAPP** 
(Command Line App) tools.
+
+CLAPP enables third-party developers and plugin authors to build and 
distribute standalone CLI utilities that run directly via the standard Maven 
launcher (`mvn --clapp <toolname>`) while maintaining **per-tool isolated 
classpaths**.
+
+---
+
+## Why CLAPP?
+
+Traditionally, adding a new CLI command to Maven required placing all of its 
third-party runtime dependencies into the shared `${maven.home}/lib/` 
directory. This created several issues:
+- **Dependency bloat**: All dependencies became part of the core Maven 
classpath.
+- **Version conflicts**: Conflicts between library versions required by 
different CLI tools and the Maven core.
+- **Lack of isolation**: Classes could accidentally leak or collide across 
tools.
+
+CLAPP solves this by isolating each tool into its own sub-directory inside 
`${maven.home}/lib/clapp/<toolname>/`.
+
+---
+
+## Architecture & Class Loading
+
+When a user executes:
+
+```bash
+mvn --clapp <toolname> [args...]
+```
+
+1. The `mvn` launcher script detects `--clapp <toolname>`.
+2. It sets the system property `maven.clapp.name=<toolname>` and reads 
`${maven.home}/lib/clapp/<toolname>/clapp.properties` to obtain the entry-point 
class.
+3. The launcher delegates to `org.apache.maven.cling.MavenClappCling`.
+4. `MavenClappCling` constructs a child `URLClassLoader` containing all 
`*.jar` files located in `${maven.home}/lib/clapp/<toolname>/`. This child 
classloader delegates to the parent core Maven classloader (the Plexus 
`plexus.core` realm).
+5. The entry-point class's `main(String[] args, ClassWorld world)` method is 
invoked via reflection.
+6. The child `URLClassLoader` is automatically closed upon completion via 
try-with-resources.
+
+This model provides two key guarantees:
+1. **Access to Maven APIs**: The tool can freely access and use Maven core 
APIs provided by the parent classloader.
+2. **Dependency Isolation**: The tool's private dependencies are NOT visible 
to the core Maven realm or to any other CLAPP tools.
+
+---
+
+## Packaging a Third-Party CLAPP
+
+### 1. Directory Structure
+
+Place your tool files in a subfolder under `${maven.home}/lib/clapp/`:
+
+```
+${maven.home}/
+  lib/
+    clapp/
+      <toolname>/
+        clapp.properties        <- Required configuration
+        my-tool-1.0.jar         <- Tool binary
+        dependency-a-2.1.jar    <- Tool private dependency

Review Comment:
   To clarify: the local repository (~/.m2/repository) remains fully available 
and used for dynamic artifact resolution at runtime. The layout shown in 
clapp.md under ${maven.home}/lib/clapp/<toolname>/ represents the 
pre-packaged/bundled distribution structure for offline standalone CLI tools 
shipped directly with Maven installation, isolating tool dependencies from the 
core Maven/plexus classpath.



-- 
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]

Reply via email to