英文:
Failed to find Premain-Class manifest attribute ... spock-mockable
问题
I am trying to stub the final class java.net.UR in my spock test. Based on the answer here: https://stackoverflow.com/questions/75691233/how-to-stub-a-java-final-static-method-or-class-in-spock I'm attempting to use spock-mockable.
I have modified my build.gradle as follows:
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}"]
}
From reading the readme file, it looks like I can now just run my test, but when I try it, I get the following error:
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
I'm not exactly sure what a javaagent is and tried to find some reading on it, but found several examples with no explanation. I can kind of guess.
At any rate, the spock-mockable shows up in my external libraries. (From IntelliJ where I'm running this test.)
Looking for what to do next.
英文:
I am trying to stub the final class java.net.UR in my spock testL. Based on the answer here: https://stackoverflow.com/questions/75691233/how-to-stub-a-java-final-static-method-or-class-in-spock I'm attempting to use spock-mockable.
I have modified my build.gradle as follows:
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}"]
}
From reading the readme file, it looks like I can now just run my test, but when I try it, I get the following error:
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
I'm not exactly sure what a javaagent is and tried to find some reading on it, but found several examples with no explanation. I can kind of guess.
At any rate, the spock-mockable shows up in my external libraries. (From IntelliJ where I'm running this test.)
Looking for what to do next.
答案1
得分: 1
Spock Mockable版本3d2e39a已经过时(2022年5月),与前导的“3”暗示的最新版本不符。根据GitHub网站和MvnRepository.com的信息,最新版本是2.3.1。
如果您检查版本3d2e39a的JAR文件,您会发现一个空的_META-INF/MANIFEST.MF_文件,这是导致错误消息的根本原因。实际上没有Premain-Class
entry在那里,这对于将JAR作为Java代理运行是必要的。但是2.3.1具有正确的清单条目。
英文:
Spock Mockable version 3d2e39a is old (May 2022), not a recent version as the leading "3" implies. According to both the GitHub site and MvnRepository.com, the latest release is 2.3.1.
If you inspect the JAR of version 3d2e39a, you will find an empty META-INF/MANIFEST.MF file, which is the root cause for your error message. There really is no Premain-Class
entry there, which would be necessary to run the JAR as a Java agent. But 2.3.1 has the correct manifest entries.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论