Maven 构建会导致使用 Java 1.7 的 VerifyError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10869127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven build causes VerifyError with java 1.7
提问by Zhivko Delchev
I got one simple class with test case for it and everything works fine in eclipse, but when I run maven build (with this goals : install cobertura:cobertura checkstyle:checkstyle-aggregate) I'm seeing a Verify error in surefire report.
我得到了一个带有测试用例的简单类,并且在 eclipse 中一切正常,但是当我运行 maven build(目标是:安装 cobertura:cobertura checkstyle:checkstyle-aggregate)时,我在surefire 报告中看到了验证错误。
Here is the exact error :
这是确切的错误:
-------------------------------------------------------------------------------
Test set: com.diploma.testProject.ClassUnderTestTest
-------------------------------------------------------------------------------
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.034 sec <<< FAILURE!
testMethodReturnsTrue(com.diploma.testProject.ClassUnderTestTest) Time elapsed: 0.005 sec <<< ERROR!
java.lang.VerifyError: Expecting a stackmap frame at branch target 79 in method com.diploma.testProject.ClassUnderTest.method(II)Z at offset 24
at com.diploma.testProject.ClassUnderTestTest.testMethodReturnsTrue(ClassUnderTestTest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.accesspublic class ClassUnderTest {
public static boolean method(int a, int b) {
if ( a == b) {
System.out.println("");
return true;
}
return false;
}
}
0(ParentRunner.java:42)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
at $Proxy0.invoke(Unknown Source)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
testMethodReturnFalse(com.diploma.testProject.ClassUnderTestTest) Time elapsed: 0 sec <<< ERROR!
java.lang.VerifyError: Expecting a stackmap frame at branch target 79 in method com.diploma.testProject.ClassUnderTest.method(II)Z at offset 24
at com.diploma.testProject.ClassUnderTestTest.testMethodReturnFalse(ClassUnderTestTest.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.accesspublic class ClassUnderTestTest {
@Test
public void testMethodReturnsTrue() {
assertTrue(ClassUnderTest.method(1, 1));
}
@Test
public void testMethodReturnFalse() throws Exception {
assertFalse(ClassUnderTest.method(1, 2));
}
}
0(ParentRunner.java:42)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
at $Proxy0.invoke(Unknown Source)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
This is the class :
这是课程:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.diploma</groupId>
<artifactId>testProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>testProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<testSource>1.7</testSource>
<testTarget>1.7</testTarget>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
And the test :
和测试:
public class ClassUnderTest {
public static boolean method(int a, int b) {
if ( a == b) {
System.out.println("");
}
return false;
}
}
And pom.xml :
和 pom.xml :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<argLine>-XX:-UseSplitVerifier</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<testSource>1.7</testSource>
<testTarget>1.7</testTarget>
</configuration>
</plugin>
</plugins>
</build>
When setting the target to 1.5 this works but I need it to work with 1.7. More strange is that modifying the method to have only one return like this :
将目标设置为 1.5 时,这有效,但我需要它与 1.7 一起使用。更奇怪的是,将方法修改为只有一个返回值,如下所示:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<testSource>1.7</testSource>
<testTarget>1.7</testTarget>
</configuration>
</plugin>
</plugins>
also fixes the problem. I've tried setting the target and source version in properties block of pom, but the result was the same.
也解决了这个问题。我试过在 pom 的属性块中设置目标和源版本,但结果是一样的。
Is there a way to make this running on version 1.7?
有没有办法让它在 1.7 版上运行?
EDIT : Also this problem appears only with goal cobertura:cobertura.
编辑:这个问题也只出现在目标 cobertura:cobertura 上。
回答by Zhivko Delchev
The problem seems to be in cobertura. Looks like it doesn't support java 1.7 very good. The fix was similar to the link that @Raghuram wrote for the eclipse. Modifying pom like this makes test works fine :
问题似乎出在 cobertura。看起来它不支持java 1.7 很好。该修复程序类似于@Raghuram 为日食编写的链接。像这样修改 pom 使测试工作正常:
##代码##回答by Raghuram
Edit: mvn cobertura:cobertura
does not work due to lack of support of cobertura for Java 7. This SO questiondiscusses this. Looks like JaCoCois the way to go.
编辑:mvn cobertura:cobertura
由于缺乏对 Java 7 的 cobertura 的支持而不起作用。 这个 SO 问题讨论了这一点。看起来JaCoCo是要走的路。
mvn install
works fine for me from command-line with maven-3.0.4
and java 1.7.0_04
on Windows 7. Possibly you are hitting this eclipse bug?
mvn install
从命令行maven-3.0.4
和java 1.7.0_04
Windows 7 上运行对我来说很好。可能你遇到了这个 Eclipse 错误?
To add to @Pau' answer, <pluginManagement>
is used in multi-module poms to declare <plugin>
elements that can be inherited as required by children.
添加到@Pau' 的答案中,<pluginManagement>
在多模块 poms 中用于声明<plugin>
可以根据子项要求继承的元素。
I get no errors with the pom
in the question as well the following snippet:
我没有收到pom
问题中的错误以及以下代码段: