Custom Lifecycle ломает 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>
в jar
от wcc
тогда мои тесты проходят и проходят просто отлично.
Итак, почему я получаю эту ошибку, и что более важно, как я могу исправить это?
Дальнейшее расследование
Плагин 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
в моем плагине, где он используется таким образом?
1 ответ
Я понял мою проблему. Я определил Mojo для фазы инициализации. Он обрабатывал мою конфигурацию и устанавливал значения по умолчанию. одно из значений, которые он устанавливал, было componentZip
, Чтобы убедиться, что он был перенесен на более поздние этапы, он хранится в свойствах, свойствах пользователя и свойствах системы. Преобразование его и кода обновления свойств в String
решил мою проблему.