自定义生命周期中断Surefire: Maven中的测试



我有一个插件,创建一个特殊的zip文件作为构建过程的一部分。
为此,它定义了一个自定义打包类型'wcc'和一个自定义生命周期。
当我运行mvn package时,应用程序构建我的zip文件很好,一切正常。
(注意:它是跳过单元测试来做到这一点。)

然而,当我运行mvn test时它失败了。

并吐出以下日志:

[ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test 
(default-test) on project LowesMMU: 
  A type incompatibility occured while executing 
   org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test: 
      java.io.File cannot be cast to java.lang.String
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.apache.maven.plugins:maven-surefire-plugin:2.19.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/.m2/repository/org/apache/maven/plugins/maven-surefire-plugin/2.19.1/maven-surefire-plugin-2.19.1.jar
[ERROR] urls[1] = file:/.m2/repository/org/apache/maven/surefire/maven-surefire-common/2.19.1/maven-surefire-common-2.19.1.jar
[ERROR] urls[2] = file:/.m2/repository/org/apache/maven/surefire/surefire-booter/2.19.1/surefire-booter-2.19.1.jar
[ERROR] urls[3] = file:/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15.jar
[ERROR] urls[4] = file:/.m2/repository/junit/junit/4.12/junit-4.12.jar
[ERROR] urls[5] = file:/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
[ERROR] urls[6] = file:/.m2/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
[ERROR] urls[7] = file:/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.11/plexus-interpolation-1.11.jar
[ERROR] urls[8] = file:/.m2/repository/org/slf4j/slf4j-jdk14/1.5.6/slf4j-jdk14-1.5.6.jar
[ERROR] urls[9] = file:/.m2/repository/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6.jar
[ERROR] urls[10] = file:/.m2/repository/org/slf4j/jcl-over-slf4j/1.5.6/jcl-over-slf4j-1.5.6.jar
[ERROR] urls[11] = file:/.m2/repository/org/apache/maven/reporting/maven-reporting-api/3.0/maven-reporting-api-3.0.jar
[ERROR] urls[12] = file:/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
[ERROR] urls[13] = file:/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[14] = file:/.m2/repository/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar
[ERROR] urls[15] = file:/.m2/repository/org/apache/maven/surefire/surefire-api/2.19.1/surefire-api-2.19.1.jar
[ERROR] urls[16] = file:/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.3/maven-plugin-annotations-3.3.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[project>com.lowes.ecm:LowesMMU:1.0.0-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]
[ERROR] 
[ERROR] -----------------------------------------------------
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

如果我将<packaging>wcc更改为jar,那么我的测试运行并通过得很好。

那么为什么我得到这个错误,更重要的是我如何修复它?


Maven surefire插件只支持java.lang.String属性。我的插件有一对java.io.File属性。

@Parameter(property = "componentZip", defaultValue = "${componentLocation}")
protected File componentZip;
@Parameter(property = "manifestFile", defaultValue = "${project.basedir}/manifest.hda")
protected File manifestFile;

这些属性被我的插件用来打包zip文件,同时适当地打包文件,并确保它是按照预期的格式构建的。

我怎样才能确保忽略这些配置属性?我需要让他们String和添加转换到File在我的插件,它是这样使用的吗?

我找到我的问题了。我为initialize阶段定义了一个Mojo。它正在处理我的配置并设置默认值。它设置的一个值是componentZip。为了确保它被迁移到后面的阶段,它将它存储在Properties、UserProperties和SystemProperties中。将它和属性更新代码转换为String解决了我的问题。

相关内容

  • 没有找到相关文章

最新更新