elharo commented on code in PR #13277: URL: https://github.com/apache/maven/pull/13277#discussion_r4115657231
########## 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 Review Comment: https ########## 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**. Review Comment: I'm not sold on CLAPP as a good name here. Is this common in other contexts? I just usually hear CLI tools, or CLI programs, or shell tools, or something like that. Don't think I've heard CLAPP before. ########## 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 + dependency-b-3.0.jar <- Tool private dependency +``` + +Tool names must consist only of alphanumeric characters, hyphens, and underscores (`^[a-zA-Z0-9_-]+$`). + +### 2. Descriptor (`clapp.properties`) + +Create a `clapp.properties` file in your tool's directory: + +```properties +# Fully-qualified class name of your tool's entry point +mainClass=org.example.mytool.MyToolCling +``` + +### 3. Entry-Point Implementation + +Your entry-point class must expose a `public static int main(String[] args, ClassWorld world)` method: + +```java +package org.example.mytool; + +import org.codehaus.plexus.classworlds.ClassWorld; + +public class MyToolCling { + + public static int main(String[] args, ClassWorld world) { Review Comment: Is this some new version of main method in Java 25 or something? If not, naming it main is just confusing. Let's use a completely different name here. ########## 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: This hits my ick button. Dependencies should be in the usual location .m2/repository. There's no need to hide them here. Maven already handles multiple versions of dependencies. and now that I think about it, the tool jar should be there too. -- 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]
