Failed to find Premain-Class manifest attribute ... spock-mockable

问题描述 投票:0回答:1

我正在尝试在我的 spock testL 中存根最后一个类 java.net.UR。基于这里的答案:How to stub a java final static method or class in Spock? I'm trying to use spock-mockable.

我修改了我的build.gradle如下:

testImplementation (
        'org.junit.jupiter:junit-jupiter-api:5.8.1',
        'org.spockframework:spock-core:2.4-M1-groovy-4.0',
        'io.github.joke:spock-mockable:3d2e39a',
        'cglib:cglib-nodep:3.3.0'
)

...

// to load the agent even earlier add it as a JVM argument
tasks.withType(Test) {
    jvmArgs += ["-javaagent:${classpath.find { it.name.contains('spock-mockable') }.absolutePath}"]
}

阅读自述文件,看起来我现在可以运行我的测试,但是当我尝试它时,我收到以下错误:

Error occurred during initialization of VM
Failed to find Premain-Class manifest attribute in /home/thomas/.gradle/caches/modules-2/files-2.1/io.github.joke/spock-mockable/3d2e39a/d3a086b4c82c8290a2013ebd5a6b697f959918bf/spock-mockable-3d2e39a.jar
agent library failed to init: instrument

我不太确定 javaagent 是什么,并试图找到一些关于它的阅读材料,但发现了几个没有解释的例子。我可以猜到。

无论如何,spock-mockable 出现在我的外部库中。 (来自我运行此测试的 IntelliJ。)

寻找下一步做什么。

java groovy jvm spock
1个回答
0
投票

Spock Mockable 版本 3d2e39a 是旧版本(2022 年 5 月),而不是前导“3”所暗示的最新版本。根据 GitHub 站点和 MvnRepository.com,最新版本是 2.3.1.

如果您检查版本 3d2e39a 的 JAR,您会发现一个空的 META-INF/MANIFEST.MF 文件,这是错误消息的根本原因。确实没有

Premain-Class
入口,这是将 JAR 作为 Java 代理运行所必需的。但是 2.3.1 有正确的清单条目。

© www.soinside.com 2019 - 2024. All rights reserved.