【问题标题】:How do I run plugins in my Maven default profile, but prevent those plugins from running if another profile is specified?如何在我的 Maven 默认配置文件中运行插件,但如果指定了另一个配置文件,则阻止这些插件运行?
【发布时间】:2013-03-25 18:18:18
【问题描述】:

我正在使用 Maven 3.0.3。我对 Maven 配置文件激活中的“activeByDefault”标志感到困惑。我想要的是有一个默认配置文件,但是如果有人指定了另一个配置文件(例如 -P 其他配置文件),则默认配置文件构建中的所有插件都不会运行。而且,如果有人指定:

mvn clean install

默认配置文件中的插件将运行,但其他配置文件中的插件不会运行。但是,默认配置文件中的插件始终在运行,即使我在命令行上指定了不同的配置文件(通过“-P 其他”)。这是我所拥有的

<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>

【问题讨论】:

    标签: maven default profile


    【解决方案1】:

    如果指定了另一个配置文件,则会禁用默认配置文件,但只有在同一个 POM 中指定了另一个配置文件

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

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

    【讨论】:

    • 奇怪,使用 maven 我觉得使用 cmd.exe,你可以做这些事情,但不希望有任何一致性或常识:/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-01
    相关资源
    最近更新 更多