2012-06-03 28 views
6

Mam jedną prostą klasę z przypadkiem testowym i wszystko działa dobrze w czasie zaćmienia, ale kiedy uruchamiam maven build (z tymi celami: zainstaluj cobertura: cobertura checkstyle: checkstyle-aggregate) I ' Widzę błąd weryfikacji w raporcie surefire.Konstrukcja Maven powoduje VerifyError z java 1.7

Oto dokładny błąd:

------------------------------------------------------------------------------- 
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$1.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$3.run(ParentRunner.java:193) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
    at org.junit.runners.ParentRunner$2.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$1.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$3.run(ParentRunner.java:193) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
    at org.junit.runners.ParentRunner$2.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) 

Jest to klasa:

public class ClassUnderTest { 
    public static boolean method(int a, int b) { 
     if (a == b) { 
      System.out.println(""); 
      return true; 
     } 
     return false; 
    } 
} 

a test:

public class ClassUnderTestTest { 

    @Test 
    public void testMethodReturnsTrue() { 
     assertTrue(ClassUnderTest.method(1, 1)); 
    } 

    @Test 
    public void testMethodReturnFalse() throws Exception { 
     assertFalse(ClassUnderTest.method(1, 2)); 
    } 

} 

I pom.xml:

<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> 

Ustawienie wartości docelowej na 1,5 działa, ale potrzebuję jej do pracy z wersją 1.7. bardziej dziwne jest to, że zmieniając metodę mieć tylko jeden zwrot takiego:

public class ClassUnderTest { 
    public static boolean method(int a, int b) { 
     if (a == b) { 
      System.out.println(""); 
     } 
     return false; 
    } 
} 

rozwiązuje również problem. Próbowałem ustawić docelową i wersję źródłową w bloku właściwości pom, ale wynik był taki sam.

Czy istnieje sposób na uruchomienie tej wersji w wersji 1.7?

EDYCJA: Ten problem pojawia się tylko z celem cobertura: cobertura.

+0

Wydaje się, że jest to powszechny problem, a bardzo podobne pytania są publikowane na SO. Wysłałem tę rezolucję, aby nasz problem został rozwiązany w następujący sposób: http://stackoverflow.com/a/20001391/1279002 – theINtoy

Odpowiedz

20

Problem wydaje się być w Cobertura. Wygląda na to, że nie obsługuje java 1.7 bardzo dobrze. Poprawka była podobna do linku, który @Raghuram napisał dla zaćmienia. Modyfikowanie pom w ten sposób sprawia, że ​​test działa dobrze:

<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> 
+0

Podobne ustawienie działa z buildr: ENV ['JAVA_OPTS'] || = "-XX: UseSplitVerifier" – Dzhaughn

4

Edit: mvn cobertura:cobertura nie działa z powodu braku wsparcia Cobertura for Java 7. This SO question omawia to. Wygląda na to, że jest to JaCoCo.

mvn install działa dobrze dla mnie z linii poleceń z maven-3.0.4 i java 1.7.0_04 na Windows 7. Prawdopodobnie jesteś uderzanie this eclipse bug?

Aby dodać do odpowiedzi @Pau ', <pluginManagement> jest używany w modułach poms do zadeklarowania elementów <plugin>, które mogą być dziedziczone zgodnie z wymaganiami dzieci.

otrzymuję żadnych błędów z pom w pytaniu, jak również następującym fragmencie:

<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> 

+0

Hm ... Mam ten sam błąd z linii poleceń, ale teraz dowiedziałem się, że to od celu cobertura : cobertura. Podczas pracy tylko instalacja działa dobrze. Dzięki za uwagę na temat

+0

@ZhivkoDelchev. Ten sam błąd występuje w przypadku 'cobertura'. Zaktualizowano odpowiedź: – Raghuram

+0

Cobertura 2.x jest nowa, obsługuje java 7. – Dzhaughn