I have a plugin that creates a special zip file as part of the build process.
To do this it defines a custom packaging type 'wcc' and a custom life cycle to go with it.
When I run mvn package
the applicaton builds my zip file just fine and everything works.
(note: it is skipping unit tests to do this.)
However, when I run mvn test
it fails.
and spits out the following log:
[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
If I change <packaging>
to jar
from wcc
then my tests run and pass just fine.
So why am I getting this error, and more importantly how do I fix it?
Further Investigation
Maven surefire plugin only supports java.lang.String
properties.
My plugin has a pair of java.io.File
properties.
@Parameter(property = "componentZip", defaultValue = "${componentLocation}")
protected File componentZip;
@Parameter(property = "manifestFile", defaultValue = "${project.basedir}/manifest.hda")
protected File manifestFile;
These properties are used by my plugin for packing the zip file, along with packaging the file appropriately and making sure it is built in the expected format.
How can I get surefire to ignore these config properties? Do I need to make them String
and add conversions to File
in my plugin where It's used that way?
I figured out my Problem. I had a Mojo defined for the initialize phase. It was processing my configuration and setting default values. one of the values it was setting was componentZip
. To make sure it got migrated to the later phases, it as storing it in Properties, UserProperties, and SystemProperties. Converting it, and the Properties update code to a String
solved my problem.