Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run plugins in my Maven default profile, but prevent those plugins from running if another profile is specified?

I'm using Maven 3.0.3. I'm confused about the "activeByDefault" flag in a Maven profile activation. What I want is to have a default profile but if someone specifies another profile (e.g. -P other profile), none of the plugins within the build of the default profile will run. And, if someone specifies:

mvn clean install

the plugins from the default profile will run, but plugins in other profiles won't run. However, the plugins in the default profile are always running, even if I specify a different profile (via "-P other") on the command line. Here is what I have

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>           
        </activation>
        <build>
            <plugins>
                <!-- Prepare liquibase scripts to run against the test db. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.7</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.mainco.subco</groupId>
                            <artifactId>database</artifactId>
                            <version>${project.version}</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>unzip-liquibase-archive</id>
                            <phase>process-test-resources</phase>
                            <configuration>
                                <target>
                                    <echo message="unzipping liquibase archive" />
                                    <unzip
                                        src="${user.home}/.m2/repository/org/mainco/subco/database/${project.version}/database-${project.version}.jar"
                                        dest="${project.build.directory}" />
                                </target>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                        <!-- Replace relative references in liquibase file with absolute ones. -->
                        <execution>
                            <id>format-liquibase-files</id>
                            <phase>process-test-resources</phase>
                            <configuration>
                                <target>
                                    <replace token='include file="'
                                        value="include file=&quot;${project.build.directory}/" file="target/db.changelog-master.xml" />
                                </target>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- Run the liquibase scripts -->
                <plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>2.0.1</version>
                    <dependencies>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>5.1.18</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>build-database</id>
                            <phase>process-test-resources</phase>
                            <configuration>
                                <driver>com.mysql.jdbc.Driver</driver>
                                <url>jdbc:mysql://${test.mysql.db.host}:${test.mysql.db.port}/${test.mysql.db.sid}</url>
                                <username>${test.mysql.db.user}</username>
                                <password>${test.mysql.db.password}</password>
                                <changeLogFile>${project.build.directory}/db.changelog-master.xml</changeLogFile>
                                <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                            </configuration>
                            <goals>
                                <goal>update</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>                   
            </plugins>
        </build>
    </profile>
    ... 
</profiles>
like image 949
Dave Avatar asked Apr 03 '13 21:04

Dave


1 Answers

Default profile is disabled if another profile is specified, but only is that other profile is specified in the same POM.

So if you have only one profile (active by default) in a pom, you won't be able to deactivate it, unless you use the -P!xxx

A solution is that you ensure that profiles that should deactivate the dev one are always present on the POM's that define that dev profile, even if these profiles are empty for some POM's.

like image 152
Tome Avatar answered Nov 17 '22 10:11

Tome