为什么 Cucumber.options 在 MAVEN_OPTS 环境变量中不起作用?
Why Cucumber.options doesn't work in the MAVEN_OPTS environment variable?
我正在查看一个 Gitlab CI 脚本,它在 MAVEN_OPTS
环境变量中定义了一些标志:
## etc...
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dspring.profiles.active=acc"
test-application:
image: maven:3.6-jdk-11
stage: test-run
script:
- mvn $MAVEN_CLI_OPTS test $MAVEN_OPTS -DCucumber.options='--glue com/example/app'
## etc...
通过上面的脚本,流水线成功。
但是,我注意到当我尝试在 MAVEN_OPTS
变量中移动 -DCucumber.options='--glue com/example/app'
标志时,例如
## etc...
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dspring.profiles.active=acc -DCucumber.options='--glue com/example/app'"
## etc...
script:
- mvn $MAVEN_CLI_OPTS test $MAVEN_OPTS
## etc...
管道现在失败并显示以下消息:
Error: Could not find or load main class com.example.app'
Caused by: java.lang.ClassNotFoundException: com.example.app'
我能够在没有 Gitlab 的情况下在本地复制它,所以我放弃了它的问题。
据我所知,MAVEN_OPTS
变量在 JVM 进程的设置期间被 Maven 使用,所以它似乎是一个我可以为我的所有 Maven 命令添加一些标志的地方,而无需我需要稍后明确添加它们。所以,从我的角度来看,这两个脚本应该是等价的。
我的理解有问题吗?如果是这样,有人可以向我解释这里出了什么问题吗?谢谢!
您可以使用以下命令重现此错误:
$ java com/example/App
Error: Could not find or load main class com.example.App
Caused by: java.lang.ClassNotFoundException: com.example.App
这表明 GitlabCI 或 Maven 正在重新解释命令行选项。看看 MSHARED-750 and cucumber-jvm/#596 可能是 Maven。
如果您使用的是 Cucumber v5+,则应使用 cucumber.glue=com.example.app
而不是 cucumber.options
。参见 Properties, Environment variables, System Options。或者,对于 v5+,您可以选择根本不提供任何胶水,因为 Cucumber 默认会从 class 路径根目录中搜索胶水 classes。
我正在查看一个 Gitlab CI 脚本,它在 MAVEN_OPTS
环境变量中定义了一些标志:
## etc...
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dspring.profiles.active=acc"
test-application:
image: maven:3.6-jdk-11
stage: test-run
script:
- mvn $MAVEN_CLI_OPTS test $MAVEN_OPTS -DCucumber.options='--glue com/example/app'
## etc...
通过上面的脚本,流水线成功。
但是,我注意到当我尝试在 MAVEN_OPTS
变量中移动 -DCucumber.options='--glue com/example/app'
标志时,例如
## etc...
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dspring.profiles.active=acc -DCucumber.options='--glue com/example/app'"
## etc...
script:
- mvn $MAVEN_CLI_OPTS test $MAVEN_OPTS
## etc...
管道现在失败并显示以下消息:
Error: Could not find or load main class com.example.app'
Caused by: java.lang.ClassNotFoundException: com.example.app'
我能够在没有 Gitlab 的情况下在本地复制它,所以我放弃了它的问题。
据我所知,MAVEN_OPTS
变量在 JVM 进程的设置期间被 Maven 使用,所以它似乎是一个我可以为我的所有 Maven 命令添加一些标志的地方,而无需我需要稍后明确添加它们。所以,从我的角度来看,这两个脚本应该是等价的。
我的理解有问题吗?如果是这样,有人可以向我解释这里出了什么问题吗?谢谢!
您可以使用以下命令重现此错误:
$ java com/example/App
Error: Could not find or load main class com.example.App
Caused by: java.lang.ClassNotFoundException: com.example.App
这表明 GitlabCI 或 Maven 正在重新解释命令行选项。看看 MSHARED-750 and cucumber-jvm/#596 可能是 Maven。
如果您使用的是 Cucumber v5+,则应使用 cucumber.glue=com.example.app
而不是 cucumber.options
。参见 Properties, Environment variables, System Options。或者,对于 v5+,您可以选择根本不提供任何胶水,因为 Cucumber 默认会从 class 路径根目录中搜索胶水 classes。