How do I get a plugin dependency from the project object in my mojo?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How do I get a plugin dependency from the project object in my mojo?

ahardy42
I've got another question about mojo development.

Sorry for cross-posting, but I've put it here too:

https://stackoverflow.com/questions/45552953/how-do-i-get-a-plugin-dependency-in-my-mojo



I created a maven plugin and I implement my plugin in the projects where I need it like below.

Note that I left the test project doesn't have any dependencies. But part of the job the plugin has to do is to retrieve a zip dependency and extract a couple of files.

I use

project.getDependencies()

and loop thro it to find that zip dependency.

If I put the dependency xml in the plugin dependencies, the plugin can't find it.

If I move the dependency xml to the dependencies for the test project, it works, but I don't think the dependency should be there. According to the maven plugin docs

    dependencies: Dependencies are seen a lot within the POM, and are an element under all plugins element blocks. The dependencies have the same structure and function as under that base build. The major difference in this case is that instead of applying as dependencies of the project, they now apply as dependencies of the plugin that they are under. The power of this is to alter the dependency list of a plugin, perhaps by removing an unused runtime dependency via exclusions, or by altering the version of a required dpendency. See above under Dependencies for more information.

So I want the dependency isolated to the plugin. I might want to run the plugin more than once and use a different dependency.

How can I get the build->plugins->plugin dependency, instead of relying on the base project?

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
         http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.testproject</groupId>
    <artifactId>test</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <dependencies>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.my-new-plugin</groupId>
                <artifactId>my-maven-plugin</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>configure</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.testproject</groupId>
                        <artifactId>configuration</artifactId>
                        <version>1.0.1</version>
                        <type>zip</type>
                    </dependency>
                </dependencies>
                <configuration>
                    <commonUniversal>common.properties</commonUniversal>
                    <projectUniversal>my-test.properties</projectUniversal>
                    <projectPerEnv>my-test-env.yml</projectPerEnv>
                    <configDependencyGroupId>com.my-other-dep</configDependencyGroupId>
                    <configDependencyArtifactId>configuration</configDependencyArtifactId>
                    <propertyFilesDestDir>config-test</propertyFilesDestDir>
                    <bundles>
                       
                            <includePattern>.*/config/deployment/ansible/Dockerfile.*</includePattern>
                            <flatten>false</flatten>
                            <srcDir>${project.basedir}/src/main/config/deployment/ansible</srcDir>
                            <targetDir>${project.build.directory}/ansible</targetDir>
                       
                       
                            <includePattern>.*/config/deployment/docker_comm.*</includePattern>
                            <flatten>true</flatten>
                            <srcDir>${project.basedir}/src/main/config/deployment</srcDir>
                            <targetDir>${project.build.directory}/docker-commands</targetDir>
                       
                       
                            <includePattern>.*/config/deployment/ansible/.*</includePattern>
                            <excludePattern>.*/config/deployment/ansible/Dockerfile.*</excludePattern>
                            <flatten>false</flatten>
                            <srcDir>${project.basedir}/src/main/config/deployment/ansible</srcDir>
                            <targetDir>${project.build.directory}/ansible</targetDir>
                       
                       
                            <includePattern>.*/config/ds-workflow.properties.*</includePattern>
                            <flatten>true</flatten>
                            <srcDir>${project.basedir}/src/main/config</srcDir>
                            <targetDir>${project.build.directory}/ds-config</targetDir>
                       
                    </bundles>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Loading...