2010-06-15 74 views
4

我们在生产中使用MySQL,单元测试使用Derby。我们的pom.xml的副本德比版测试之前的persistence.xml,并与MySQL的版本替代它,准备封装阶段:如何防止mvn码头:从执行测试阶段运行?

<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之前测试persistence.xml文件复制任务。我希望它使用部署版本运行。我怎样才能解决这个问题?

回答

2

jetty:run目标在执行自身之前调用执行生命周期阶段test-compile。所以跳过测试执行不会改变任何东西。

您需要做的是将copy-test-persistence执行绑定到test-compile后面的生命周期阶段,但是在test之前。并且有十二名候选人,但只有一个: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> 
相关问题