Quarkus @QuarkusTest独立测试JAR在项目目录外运行失败问题求助
Quarkus @QuarkusTest独立测试JAR在项目目录外运行失败问题求助
各位好,我现在碰到一个头疼的问题:我有个基于Quarkus 3.16.3 + Gradle的项目,用@QuarkusTest来跑Cucumber测试。我生成了一个独立的测试运行JAR,本来想着能在任意目录执行测试,结果发现只有在原项目的根目录下运行才正常,换到其他目录就直接报错了,想请教大家有没有解决思路?
正常运行的场景
当我在项目主目录下执行以下命令时,测试全程正常,Docker、Testcontainers都能顺利启动,Cucumber测试也能跑完:
java -jar build/libs/test-1.0.0-SNAPSHOT-test-runner.jar
对应的正常运行日志如下:
Running Cucumber tests with HTTP server disabled... Using profile: stg Features location: classpath:features 💚 Thanks for using JUnit! Support its development at https://junit.org/sponsoring Jun 27, 2025 7:28:50 PM io.quarkus.bootstrap.utils.BuildToolHelper enableGradleAppModel INFO: Loading Quarkus Gradle application model for /MRepos/build-verification-test 2025-06-27 19:30:26 INFO [or.te.DockerClientFactory] (build-84) Testcontainers version: 1.20.2 2025-06-27 19:30:27 INFO [or.te.do.DockerClientProviderStrategy] (build-84) Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first 2025-06-27 19:30:28 INFO [or.te.do.DockerClientProviderStrategy] (build-84) Found Docker environment with local Unix socket (unix:///var/run/docker.sock) 2025-06-27 19:30:28 INFO [or.te.DockerClientFactory] (build-84) Docker host IP address is localhost 2025-06-27 19:30:28 INFO [or.te.DockerClientFactory] (build-84) Connected to docker: Server Version: 27.5.1 API Version: 1.47 Operating System: Docker Desktop Total Memory: 7836 MB Labels: 2025-06-27 19:30:28 INFO [or.te.im.PullPolicy] (build-84) Image pull policy will be performed by: DefaultPullPolicy() 2025-06-27 19:30:28 INFO [or.te.ut.ImageNameSubstitutor] (build-84) Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor') 2025-06-27 19:30:29 INFO [tc.lo.7.2] (build-84) LOCALSTACK_HOST environment variable set to localstack-d4udd (to match last network alias on container with non-default network) 2025-06-27 19:30:29 INFO [tc.lo.7.2] (build-84) Creating container for image: localstack/localstack:3.7.2 2025-06-27 19:30:30 INFO [or.te.ut.RegistryAuthLocator] (build-84) Credential helper/store (docker-credential-desktop) does not have credentials for https://index.docker.io/v1/ 2025-06-27 19:30:30 INFO [tc.te.9.0] (build-84) Creating container for image: testcontainers/ryuk:0.9.0 Jun 27, 2025 7:30:30 PM io.quarkus.deployment.steps.ClassTransformingBuildStep handleClassTransformation WARN: Cannot transform java.lang.String as its containing application archive could not be found. 2025-06-27 19:30:34 INFO [tc.te.9.0] (build-84) Container testcontainers/ryuk:0.9.0 is starting: 03aa4b2d2895d81d2966c00de87bbb2bd4cc2045dd2ee74bfb3753d142a7bd3c 2025-06-27 19:30:35 INFO [tc.te.9.0] (build-84) Container testcontainers/ryuk:0.9.0 started in PT5.309733S 2025-06-27 19:30:36 INFO [tc.lo.7.2] (build-84) Container localstack/localstack:3.7.2 is starting: 29eb386e7b7880028f3412e39c45ebb9388829d7242359248c2f89cba471236e 2025-06-27 19:30:40 INFO [tc.lo.7.2] (build-84) Container localstack/localstack:3.7.2 started in PT11.100043S Jun 27, 2025 7:30:40 PM io.quarkus.amazon.common.deployment.DevServicesLocalStackProcessor lambda$startLocalStack$28 INFO: Amazon Dev Services for localstack (dynamodb) started. Other Quarkus applications in dev mode will find the LocalStack automatically. Jun 27, 2025 7:30:41 PM io.quarkus.runtime.configuration.ConfigDiagnostic unknown INFO: Profile stg activated. Jun 27, 2025 7:30:42 PM io.quarkus.bootstrap.runner.Timing printStartupTime INFO: Installed features: [amazon-dynamodb, amazon-dynamodb-enhanced, cdi, config-yaml, cucumber, rest, rest-client, rest-client-jackson, smallrye-context-propagation, vertx]
运行失败的情况
只要我切换到其他目录(比如/Users/user/Downloads),执行完全一样的命令,就会报错。错误日志如下:
Running Cucumber tests with HTTP server disabled... Using profile: stg Features location: classpath:features Jun 27, 2025 7:32:38 PM org.jboss.logmanager.JBossLoggerFinder getLogger ERROR: The LogManager accessed before the "java.util.logging.manager" system property was set to "org.jboss.logmanager.LogManager". Results may be unexpected. 💚 Thanks for using JUnit! Support its development at https://junit.org/sponsoring BasicLoggingEnabler failed to enable basic logging: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException Jun 27, 2025 7:32:39 PM io.quarkus.bootstrap.utils.BuildToolHelper findBuildTool WARN: Unable to find a build tool in /Users/user/Downloads or in any parent. Jun 27, 2025 7:32:39 PM io.quarkus.bootstrap.BootstrapAppModelFactory resolveAppModel WARN: Unable to locate the maven project on the filesystem
从错误日志能看出来,Quarkus在尝试找构建工具(Gradle),但非项目目录里根本没有;同时还有LogManager的初始化问题。我本来以为这个测试JAR是完全独立的,不需要依赖原项目的构建文件,现在看来显然不是。有没有办法让这个测试JAR真正实现独立运行,不用绑定原项目目录呢?麻烦大家给点建议,谢谢!
内容来源于stack exchange
相关产品推荐
相关产品推荐

