如何在Maven默认配置文件中运行插件,但如果指定了其他配置文件,则防止这些插件运行?

6

我正在使用Maven 3.0.3版本。我对Maven配置文件中的“activeByDefault”标记感到困惑。我的需求是设置一个默认配置文件,但如果有人指定了其他配置文件(例如-P other profile),则不会运行默认配置文件中的任何插件。同时,如果有人指定:

mvn clean install

默认配置文件中的插件将运行,但在其他配置文件中的插件将不会运行。然而,默认配置文件中的插件始终在运行,即使我在命令行上指定了不同的配置文件(通过“-P other”)。下面是我的代码:

<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>
1个回答

4

如果在同一个POM中指定了另一个配置文件,则默认配置文件将被禁用, 但仅限于该另一配置文件在同一个POM中被指定

因此,如果在一个POM中只有一个配置文件(默认情况下处于活动状态),您将无法停用它,除非使用 -P!xxx。

一个解决方案是确保应该停用开发配置文件的配置文件始终存在于定义该开发配置文件的POM中,即使这些配置文件对于某些POM为空。


1
用Maven工作的时候,感觉就像在使用cmd.exe一样奇怪。你可以完成任务,但不要指望有任何一致性或常识 :/ - akostadinov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接