4

本番環境では MySQL を使用し、単体テストには Derby を使用しています。pom.xml は、テストの前に Derby バージョンの persistence.xml をコピーし、パッケージ準備段階で MySQL バージョンに置き換えます。

 <plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.3</version>
  <executions>
   <execution>
    <id>copy-test-persistence</id>
    <phase>process-test-resources</phase>
    <configuration>
     <tasks>
      <!--replace the "proper" persistence.xml with the "test" version-->
      <copy
       file="${project.build.testOutputDirectory}/META-INF/persistence.xml.test"
       tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
       overwrite="true" verbose="true" failonerror="true" />
     </tasks>
    </configuration>
    <goals>
     <goal>run</goal>
    </goals>
   </execution>
   <execution>
    <id>restore-persistence</id>
    <phase>prepare-package</phase>
    <configuration>
     <tasks>
      <!--restore the "proper" persistence.xml-->
      <copy
       file="${project.build.outputDirectory}/META-INF/persistence.xml.production"
       tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
       overwrite="true" verbose="true" failonerror="true" />
     </tasks>
    </configuration>
    <goals>
     <goal>run</goal>
    </goals>
   </execution>
  </executions>
 </plugin>

問題は、mvn jetty:run を実行すると、jetty を開始する前にテストの persistence.xml ファイル コピー タスクが実行されることです。展開バージョンを使用して実行したい。どうすればこれを修正できますか?

4

2 に答える 2

6

コマンドラインに引数-Dmaven.test.skip=true または -DskipTests=trueを追加してみてください。例えば

mvn -DskipTests=true jetty:run ...

ただし、これが process-test-resources フェーズをスキップするかどうかはわかりません。

テストのスキップに関する詳細は、Surefire プラグインのドキュメント を参照してください。

于 2010-06-15T12:00:13.640 に答える
2

jetty:runゴールは、それ自体を実行する前に、ライフサイクル フェーズの実行を呼び出しtest-compileます。したがって、テストの実行をスキップしても何も変わりません。

あなたがする必要があるのは、copy-test-persistence実行をライフサイクルフェーズの後test-compile、前にバインドすることtestです。そして、候補は数十ではなく、1 つだけですprocess-test-classes

これは概念的には理想的ではないかもしれませんが、最も悪いオプションであり、機能します。

 <plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.3</version>
  <executions>
   <execution>
    <id>copy-test-persistence</id>
    <phase>process-test-classes</phase>
    <configuration>
     <tasks>
      <!--replace the "proper" persistence.xml with the "test" version-->
      <copy
       file="${project.build.testOutputDirectory}/META-INF/persistence.xml.test"
       tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
       overwrite="true" verbose="true" failonerror="true" />
     </tasks>
    </configuration>
    <goals>
     <goal>run</goal>
    </goals>
   </execution>
   ...
  </executions>
 </plugin>
于 2010-06-15T12:57:54.497 に答える