How to access a plugin in a maven child module from the parent module

195 views Asked by At

I have a maven multi-module setup, which includes the fabric8 plugin in a profile defined in a child module to build a Docker image if the profile is active, see below

Root pom

<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.mycompany</groupId>
    <artifactId>root</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>control</name>
    <packaging>pom</packaging>

    <modules>
        <module>parent</module>
        <module>docker</module>
        <module>...</module>
        <module>...</module>
        <module>...</module>
    </modules>
</project>

Child pom

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>docker</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <profiles>
        <profile>
            <id>Docker</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>0.34.1</version>
                        <dependencies>
                            <dependency>
                                <groupId>com.amazonaws</groupId>
                                <artifactId>aws-java-sdk-core</artifactId>
                                <version>${aws.version}</version>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <registry>${aws.ecr.registry}</registry>
                            <images>
                                <image>
                                    <name>${aws.ecr.registry}/${aws.ecr.repository}:${project.artifactId}-${project.version}</name>
                                    <build>
                                        <contextDir>${project.build.directory}/docker.tmp/</contextDir>
                                    </build>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <id>docker-build</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>docker-push</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>push</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

Runing a normal build, i.e. mvn clean install -PDocker completes successfully, but if I call one of the docker goals from the parent module directly, e.g. mvn -PDocker docker:help it fails with this error

No plugin found for prefix 'docker' in the current project and in the plugin groups 

Running the same command from the docker directory completes successfully.

What changes are needed so the command completes successfully in the root directory?

0

There are 0 answers