Home > Back-end >  Inject Maven Plugin Dependencies runtime
Inject Maven Plugin Dependencies runtime

Time:09-27

is it possible to inject dependencies in maven plugin and/or gradle plugin at runtime. I know you can add dependencies in plugin in pom.xml but i want those dependencies to be runtime as i want to be able to inject them something like this mvn <plugin>:<goal> <arg=pass dependencies here)

This plugin is not in repo pom.xml so i want to run mvn cli to execute this plugin outside of the project, another option is to add a profile in settings.xml and add this plugin information there but again i have to hardcode the dependencies in there. Has anyone done this

Add Plugin Dependencies Runtime

CodePudding user response:

use tag for doing this. sample below here :

   <dependency>
        <groupId>groupId</groupId>
        <artifactId>artifactId</artifactId>
        <version>version</version>
        <scope>runtime</scope>
   </dependency>

CodePudding user response:

You could define an additional property like:

<properties>
    <plugin.dependency.version>someDefaultVersion</plugin.dependency.version>
</properties>

and use it in the plugin

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${spring-boot.verision}</version>
            <dependencies>
                <dependency>
                    <groupId>groupid</groupId>
                    <artifactId>artifactId</artifactId>
                    <version>${plugin.dependency.version}</version>
                </dependency>
            </dependencies>
        </plugin>

By doing so you should be able to define plugin's dependency via command line using this command:

mvn org.springframework.boot:spring-boot-maven-plugin:yourGoal -Dplugin.dependency.version=runtimeDepenencyVersion
  • Related