如何强制Maven下载所有测试插件而不运行任何测试? 问题:

如何强制Maven下载所有测试插件而不运行任何测试? 问题:,maven,Maven,我们有一个用于Maven依赖项的内部公司Artifactory服务器。我们有一个专门的Maven项目和测试用例,我们的一些内部库用于这个项目。可以从我们的CI访问Artifactory服务器,因此在构建过程中可以提取所有工件 我们的目标是在私有集群中的Docker容器中运行来自该项目的测试,而不访问内部存储库-出于实际目的,我们可以假设脱机调用mvn test 这意味着,作为构建过程的一部分,我希望将测试项目和所有必需的依赖项打包到Docker映像中,这样我就可以在脱机环境中安全地运行测试,而无

我们有一个用于Maven依赖项的内部公司Artifactory服务器。我们有一个专门的Maven项目和测试用例,我们的一些内部库用于这个项目。可以从我们的CI访问Artifactory服务器,因此在构建过程中可以提取所有工件

我们的目标是在私有集群中的Docker容器中运行来自该项目的测试,而不访问内部存储库-出于实际目的,我们可以假设脱机调用
mvn test

这意味着,作为构建过程的一部分,我希望将测试项目和所有必需的依赖项打包到Docker映像中,这样我就可以在脱机环境中安全地运行测试,而无需提取任何内容

我的做法: 当前的方法是确保.m2 repo是映像的一部分,然后在Dockerfile中调用此命令:

mvn clean install -DskipTests
该命令下载许多Maven插件(因此它们现在位于.m2/repository中)

然后在测试环境中,我调用:

mvn test -o
但是,后一个命令在运行容器时会产生错误:

[INFO] Scanning for projects...
(...)
[INFO]
[INFO] Building test-project 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /workspace/test-project/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-project ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-project ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ test-project ---
[WARNING] Missing POM for org.apache.maven.surefire:surefire-junit-platform:jar:2.22.2
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.908 s
[INFO] Finished at: 2019-12-12T07:43:40Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project test-project: Unable to generate classpath: org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
[ERROR] ----------
[ERROR] 1) org.apache.maven.surefire:surefire-junit-platform:jar:2.22.2
[ERROR]
[ERROR]   Try downloading the file manually from the project website.
[ERROR]
[ERROR]   Then, install it using the command:
[ERROR]       mvn install:install-file -DgroupId=org.apache.maven.surefire -DartifactId=surefire-junit-platform -Dversion=2.22.2 -Dpackaging=jar -Dfile=/path/to/file
[ERROR]
[ERROR]   Alternatively, if you host your own repository you can deploy the file there:
[ERROR]       mvn deploy:deploy-file -DgroupId=org.apache.maven.surefire -DartifactId=surefire-junit-platform -Dversion=2.22.2 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR]
[ERROR]   Path to dependency:
[ERROR]     1) dummy:dummy:jar:1.0
[ERROR]     2) org.apache.maven.surefire:surefire-junit-platform:jar:2.22.2
[ERROR]
[ERROR] ----------
[ERROR] 1 required artifact is missing.
[ERROR]
[ERROR] for artifact:
[ERROR]   dummy:dummy:jar:1.0
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR]   central (http://company-repo.org/artifactory/plugins-release, releases=true, snapshots=false),
[ERROR]   snapshots (http://company-repo.org.org/artifactory/plugins-snapshot, releases=true, snapshots=true)
[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/MojoExecutionException
我不确定dummy.jar是否是我的项目设置的一部分,但我认为这个错误可以忽略

在我看来,
org.apache.maven.surefire:surefirejunit平台
插件不可用。当我查看build命令输出时,我确认它在没有调用这个插件的情况下成功了(因此也没有将它拉到本地存储库):

所以问题是:我如何准备Maven在“脱机”模式下运行测试,而不实际运行测试

  • 我可以在build命令中运行所有测试,但这会浪费大量时间,而且结果也毫无用处(测试只会在孤立的集群中产生有意义的结果)
  • 我尝试使用选项
    -Dtest
    和“不匹配”模式,但插件没有被拉出来(显然只有在有一些测试要运行时它才会激活)
  • 我尝试了
    mvn dependency:go offline
    ,它引入了数百个依赖项,但没有用于测试的依赖项
  • 我可以向pom.xml中的所有测试插件添加显式依赖项,但这将成为维护负担(难以升级版本,可能需要多个插件等)

  • 看看,也许会有帮助。开发它是为了解决maven依赖插件的一些问题

    你能解释一下为什么你不想让Docker容器访问你的人工工厂吗?@JFMeier公司的政策,可能是一些安全要求。我总是会先尝试更改公司的政策,只有当结果证明这是不可能的时候,才尝试围绕它来构建。公司政策不是法律。与标题相反,我在创建图像期间进行了虚拟/空测试,并下载了所有依赖项,以便脱机运行测试。谢谢。文档中的一段回答了我的问题:动态依赖项是在运行时加载的。显然,我无论如何都需要指定插件版本,因为没有办法使其自动化。我想我会采用这种方法。
    mvn clean install -DskipTests
    
    (...)
    [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ test-project ---
    [INFO] Tests are skipped.
    [INFO]
    [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-project ---
    (...)