【问题标题】:How can I get maven to run mySQL plug at "mvn test"如何让 maven 在“mvn test”处运行 mySQL 插件
【发布时间】:2013-01-30 16:42:59
【问题描述】:

如何让 maven 每次运行“mvn test”时运行以下插件。

我不想每次运行时都发出“mvn sql:execute”

<plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>sql-maven-plugin</artifactId>

                        <!-- JDBC Driver -->
                        <dependencies>
                            <dependency>
                                <groupId>mysql</groupId>
                                <artifactId>mysql-connector-java</artifactId>
                                <version>5.0.5</version>
                            </dependency>
                        </dependencies>

                        <configuration>
                            <driver>com.mysql.jdbc.Driver</driver>
                            <url>jdbc:mysql://localhost:3306/jboss</url>
                            <username>xxx</username>
                            <password>xxxx</password>
                            <autocommit>true</autocommit>
                            <onError>continue</onError>
                            <srcFiles>
                                <srcFile>src/test/sql/removeuser.sql</srcFile>
                            </srcFiles>
                        </configuration>

                    </plugin>

【问题讨论】:

    标签: java mysql maven


    【解决方案1】:

    我正是为此目的创建了jcabi-mysql-maven-plugin。它在pre-integration-test 阶段启动MySQL 服务器,并在post-integration-test 阶段关闭它。

    【讨论】:

      【解决方案2】:

      您可以通过在插件标签内添加以下内容将您的目标(sql:execute)绑定到测试阶段:

                  <executions>
                      <execution>
                          <id>execute-sql</id>
                          <phase>test</phase>
                          <goals>
                              <goal>execute</goal>
                          </goals>
                      </execution>
                  </executions>
      

      【讨论】:

      • 我建议将其放入 process-test-resources 阶段,以确保它在测试之前执行。在这种情况下,它可能不会 100% 确定在测试之前执行。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      • 2018-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-14
      • 1970-01-01
      相关资源
      最近更新 更多