Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么Cucumber.options在MAVEN_OPTS环境变量中不起作用?_Java_Maven_Cucumber - Fatal编程技术网

Java 为什么Cucumber.options在MAVEN_OPTS环境变量中不起作用?

Java 为什么Cucumber.options在MAVEN_OPTS环境变量中不起作用?,java,maven,cucumber,Java,Maven,Cucumber,我在看一个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

我在看一个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变量是MAVEN在JVM过程的设置过程中使用的,因此它似乎是一个我可以为所有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正在重新解释命令行选项。看看,很可能是Maven


如果您使用Cucumber v5+,则应使用Cucumber.glue=com.example.app而不是Cucumber.options。看见或者,对于v5+,您可以选择根本不提供任何粘合,因为Cucumber默认情况下会从类路径根搜索粘合类。

实际上,在使用MAVEN_OPTS时,-DCucumber.options='-glue com/example/app'命令中的空格似乎存在问题。谢谢