Marceau
Marceau

Reputation: 1703

Maven conditional plugin execution with a twist

We will start deploying assets (js/css) over SSH with maven-wagon-plugin. We have quite a lot of profiles (>20). Not all of them will be subject to this new deploy.

To avoid exploding the size of the pom, I came up with the following solution.

I add the following under the global build section:

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>wagon-maven-plugin</artifactId>
                    <configuration>
                        <serverId>deploytarget</serverId>
                        <fromDir>src/main/resources/assets/</fromDir>
                        <url>scp://deploytarget.net:/var/www/assets/</url>
                    </configuration>
                    <executions>
                        <execution>
                            <id>push-assets</id>
                            <phase>${asset.phase}</phase>
                            <goals>
                                <goal>upload</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

I then define, under global properties

<asset.phase></asset.phase>

For those profiles that require this deploy, I add the following:

<asset.phase>deploy</asset.phase>

This seems to work: profiles without the property simply do not run the plugin execution. In addition, it saves 20 * 18 lines (+-20).

Initially, I was looking for a way to explicitly trigger an different profile from inside a profile. That is not an option. In addition, there doesn't seem to be a way for profiles to inherit from an ancestor profile.

My question: is there a reason why this would not be a good idea?

Upvotes: 2

Views: 386

Answers (1)

gizmo
gizmo

Reputation: 11909

I don't know specificly about your build, but 20+ profile seems rather unusual. Maybe you could benefit from this extension: https://github.com/sviperll/ozymandias/tree/master/maven-profiledep-extension

Upvotes: 1

Related Questions