groovy / GMavenPlus

A rewrite of GMaven, a Maven plugin for Groovy
Other
285 stars 35 forks source link

generateTestStubs failed: Unrecognized target bytecode: '8' #205

Closed QBH-insist closed 2 years ago

QBH-insist commented 2 years ago

hi, i have a compile problem when i try to use spock and gmavenplus.

command: mvn test result: image

java version: "1.8.0_151"

parent pom.xml:

        <groovy.version>2.5.14</groovy.version>
        <spock.version>1.3-groovy-2.5</spock.version>
        <powermock.version>2.0.4</powermock.version>
         <!-- spock -->
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>${spock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-spring</artifactId>
            <version>${spock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <type>pom</type>
            <version>${groovy.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>groovy-test-junit5</artifactId>
                    <groupId>org.codehaus.groovy</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>groovy-testng</artifactId>
                    <groupId>org.codehaus.groovy</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
         <build>
            <finalName>demo</finalName>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.gmavenplus</groupId>
                    <artifactId>gmavenplus-plugin</artifactId>
                    <version>1.13.1</version>
                    <executions>
                        <execution>
                          <goals>
                              <goal>addSources</goal>
                              <goal>addTestSources</goal>
                              <goal>generateStubs</goal>
                              <goal>compile</goal>
                              <goal>generateTestStubs</goal>
                              <goal>compileTests</goal>
                              <goal>removeStubs</goal>
                              <goal>removeTestStubs</goal>
                          </goals>
                      </execution>
                  </executions>
              </plugin>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-surefire-plugin</artifactId>
                  <version>3.0.0-M5</version>
                  <configuration>
                      <includes>
                          <include>**/*Spec.class</include>
                          <include>**/*Test.java</include>
                      </includes>
                  </configuration>
              </plugin>
          </plugins>
        </build>
keeganwitt commented 2 years ago

My guess is that you have maven.compiler.target set to 8. It should be 1.8. If for some reason that doesn't work for you, you can do

<configuration>
    <targetBytecode>1.8</targetBytecode>
<configuration>

in the GmavenPlus plugin element.

QBH-insist commented 2 years ago

My guess is that you have maven.compiler.target set to 8. It should be 1.8. If for some reason that doesn't work for you, you can do

<configuration>
    <targetBytecode>1.8</targetBytecode>
<configuration>

in the GmavenPlus plugin element.

You are right,thanks. Now i meet another problem, The file can compile but not run. Look forward to your reply. image image

keeganwitt commented 2 years ago

Your Spock test files are named like *Spec.groovy, right? Because your Surefire configuration currently expects that.

QBH-insist commented 2 years ago

My guess is that you have maven.compiler.target set to 8. It should be 1.8. If for some reason that doesn't work for you, you can do

<configuration>
    <targetBytecode>1.8</targetBytecode>
<configuration>

in the GmavenPlus plugin element.

You are right,thanks. Now i meet another problem, The file can compile but not run. Look forward to your reply. image image

I found the reason why test not run. I excluded 'junit-vintage-engine' dependency, this is wrong. Thanks

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
           <!-- <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>-->
        </dependency>
keeganwitt commented 2 years ago

I'm glad you were able to get it working. I'll close this issue now, but if you have further problems, let me know and I'll re-open.