我尝试将我的 Maven 项目运行到 Maven 容器中,但没有成功。在 Windows 中,我曾经使用以下命令运行所有测试,它工作正常,但在“maven:3.6.3-jdk-8”容器中返回未知生命周期错误。
mvn clean install -Ptest OR mvn test -Ptest
> [ERROR] Unknown lifecycle phase "clean install". You must specify a > valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> > or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. > Available lifecycle phases are: validate, initialize, > generate-sources, process-sources, generate-resources, > process-resources, compile, process-classes, generate-test-sources, > process-test-sources, generate-test-resources, process-test-resources, > test-compile, process-test-classes, test, prepare-package, package, > pre-integration-test, integration-test, post-integration-test, verify, > install, deploy, pre-clean, clean, post-clean, pre-site, site, > post-site, site-deploy. -> [Help 1]
我的 POM.xml 文件。
<profiles>
<profile>
<id>test</id>
<properties>
<suiteXmlFile>${basedir}\src\test\resources\project\test.xml</suiteXmlFile>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>testMore</id>
<properties>
<suiteXmlFile>${basedir}\src\test\resources\project\testMore.xml</suiteXmlFile>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
我的 dockerfile 命令
ENTRYPOINT ["mvn", "test","-Ptest"]
或者
ENTRYPOINT ["mvn", "clean install -P test"]
每当我将 ${suiteXmlFile}
替换为 ${basedir}\src\test\resources\project\test.xml
并运行 ENTRYPOINT ["mvn", "test"]
容器时,都会执行 test.xml 中列出的所有测试。
我已经使用 -Dresources=test.xml 进行了验证,它也对我不起作用,即使我尝试过测试并给出目标/阶段,但对我来说没有运气。
最佳答案
您指定的内容:
ENTRYPOINT ["mvn", "clean install -P test"]
在容器上执行为:
mvn "clean install -P test"
它将“clean install -P test”视为传递给
的单个参数
Maven 程序不将整个 token “clean install -P test”视为有效的生命周期阶段。
您想要的执行形式是:
ENTRYPOINT ["mvn", "clean", "install", "-P", "test"]
或者使用 shell 形式:
ENTRYPOINT mvn clean install -P test
关于java - 如果 test/clean install/package 命令带有 args(-D) 或配置文件标记 (-P),Maven 容器不会运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60428321/