groovy / GMavenPlus

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

Unrecognized target bytecode: '8' #223

Closed xiumin1993 closed 2 years ago

xiumin1993 commented 2 years ago

I'm using gmavenplus-plugin 1.13.1 when I setting maven

<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>

cmd

mvn test

get error

Caused by: java.lang.IllegalArgumentException: Unrecognized target bytecode: '8'.
    at org.codehaus.gmavenplus.mojo.AbstractCompileMojo.verifyGroovyVersionSupportsTargetBytecode (AbstractCompileMojo.java:544)
    at org.codehaus.gmavenplus.mojo.AbstractCompileMojo.doCompile (AbstractCompileMojo.java:314)
    at org.codehaus.gmavenplus.mojo.CompileTestsMojo.execute (CompileTestsMojo.java:77)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)

Maybe should add java version 6 to 8 in this function

  /**
     * Throws an exception if targetBytecode is not supported with this version of Groovy. That is, when Groovy added
     * the option to org.codehaus.groovy.control.CompilerConfiguration and used it in
     * org.codehaus.groovy.classgen.asm.WriterController.
     */
    protected void verifyGroovyVersionSupportsTargetBytecode() {
        if ("18".equals(targetBytecode)) {
            if (groovyOlderThan(GROOVY_4_0_0_BETA1)) {
                throw new IllegalArgumentException("Target bytecode 18 requires Groovy " + GROOVY_4_0_0_BETA1 + " or newer.");
            }
        } else if ("17".equals(targetBytecode)) {
            if (groovyOlderThan(GROOVY_3_0_8) || (groovyAtLeast(GROOVY_4_0_0_ALPHA1) && groovyOlderThan(GROOVY_4_0_0_ALPHA3))) {
                throw new IllegalArgumentException("Target bytecode 17 requires Groovy " + GROOVY_3_0_8 + "/" + GROOVY_4_0_0_ALPHA3 + " or newer.");
            }
        } else if ("16".equals(targetBytecode)) {
            if (groovyOlderThan(GROOVY_3_0_6)) {
                throw new IllegalArgumentException("Target bytecode 16 requires Groovy " + GROOVY_3_0_6 + " or newer.");
            }
        } else if ("15".equals(targetBytecode)) {
            if (groovyOlderThan(GROOVY_3_0_3)) {
                throw new IllegalArgumentException("Target bytecode 15 requires Groovy " + GROOVY_3_0_3 + " or newer.");
            }
        } else if ("14".equals(targetBytecode)) {
            if (groovyOlderThan(GROOVY_3_0_0_BETA2)) {
                throw new IllegalArgumentException("Target bytecode 14 requires Groovy " + GROOVY_3_0_0_BETA2 + " or newer.");
            }
        } else if ("13".equals(targetBytecode)) {
            if (groovyOlderThan(GROOVY_2_5_7) || (groovyAtLeast(GROOVY_2_6_0_ALPHA1) && groovyOlderThan(GROOVY_3_0_0_BETA1))) {
                throw new IllegalArgumentException("Target bytecode 13 requires Groovy " + GROOVY_2_5_7 + "/" + GROOVY_3_0_0_BETA1 + " or newer. No 2.6 version is supported.");
            }
        } else if ("12".equals(targetBytecode) || "11".equals(targetBytecode) || "10".equals(targetBytecode)) {
            if (groovyOlderThan(GROOVY_2_5_3) || (groovyAtLeast(GROOVY_2_6_0_ALPHA1) && groovyOlderThan(GROOVY_3_0_0_ALPHA4))) {
                throw new IllegalArgumentException("Target bytecode 10, 11, or 12 requires Groovy " + GROOVY_2_5_3 + "/" + GROOVY_3_0_0_ALPHA4 + " or newer. No 2.6 version is supported.");
            }
        } else if ("9".equals(targetBytecode)) {
            if (!isGroovyIndy() && (groovyOlderThan(GROOVY_2_5_3)
                    || (groovyAtLeast(GROOVY_2_6_0_ALPHA1) && groovyOlderThan(GROOVY_2_6_0_ALPHA4))
                    || (groovyAtLeast(GROOVY_3_0_0_ALPHA1) && groovyOlderThan(GROOVY_3_0_0_ALPHA2)))) {
                throw new IllegalArgumentException("Target bytecode 9 requires Groovy " + GROOVY_2_5_3 + "/" + GROOVY_2_6_0_ALPHA4 + "/" + GROOVY_3_0_0_ALPHA2 + " or newer.");
            } else if (isGroovyIndy() && (groovyOlderThan(GROOVY_2_5_3) || (groovyAtLeast(GROOVY_2_6_0_ALPHA1) && groovyOlderThan(GROOVY_3_0_0_ALPHA4)))) {
                throw new IllegalArgumentException("Target bytecode 9 with invokedynamic requires Groovy " + GROOVY_2_5_3 + "/" + GROOVY_3_0_0_ALPHA4 + " or newer. No 2.6 version is supported.");
            }
        } else if ("1.8".equals(targetBytecode)) {
            if (groovyOlderThan(GROOVY_2_3_3)) {
                throw new IllegalArgumentException("Target bytecode 1.8 requires Groovy " + GROOVY_2_3_3 + " or newer.");
            }
        } else if ("1.7".equals(targetBytecode) || "1.6".equals(targetBytecode)) {
            if (groovyOlderThan(GROOVY_2_1_3)) {
                throw new IllegalArgumentException("Target bytecode 1.6 and 1.7 require Groovy " + GROOVY_2_1_3 + " or newer.");
            }
        } else if (!"1.5".equals(targetBytecode) && !"1.4".equals(targetBytecode)) {
            throw new IllegalArgumentException("Unrecognized target bytecode: '" + targetBytecode + "'.");
        }
    }
keeganwitt commented 2 years ago

Hmm. I thought all releases prior to 9 had to have the 1. in front of them. It appears this behavior in javac has changed. Do you know where the list of targets recognized by javac might be documented (I suppose that could differ between different JDK implementations).

keeganwitt commented 2 years ago

It's also worth noting you can use skipBytecodeCheck to skip this verification.

xiumin1993 commented 2 years ago

I tried it .do not work

发自我的iPhone

------------------ Original ------------------ From: Keegan Witt @.> Date: Fri,Jul 1,2022 10:44 PM To: groovy/GMavenPlus @.> Cc: xiumin1993 @.>, Author @.> Subject: Re: [groovy/GMavenPlus] Unrecognized target bytecode: '8' (Issue#223)

It's also worth noting you can use skipBytecodeCheck to skip this verification.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

keeganwitt commented 2 years ago

I can't find the source code for it, but it looks like the synonyms are what you'd expect (https://docs.oracle.com/en/java/javase/11/tools/javac.html#GUID-AEEC9F07-CB49-4E96-8BC7-BCC2C7F725C9). I'll add these.

In the mean time, it works for me with the below XML

<properties>
  <skipBytecodeCheck>true</skipBytecodeCheck>
</properties>
keeganwitt commented 2 years ago

Actually, I'm remembering why I implemented it this way now. It's because while javac accepts both 1.8 and 8, Groovy does not. See https://github.com/apache/groovy/blob/38c85f371128b6bc46ba952228640d433b1c799e/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java

I suggest either

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

Since this would be equivalent and works for both javac and groovyc, or

<targetBytecode>1.8</targetBytecode>

The second of these can be placed in <properties> or in the <configuration> of GMavenPlus or one of its <execution>s.

xiumin1993 commented 2 years ago

Thanks for your reply   ,You guys do the great things I made a mistake  setting  skipBytecodeCheck=false
you're rigth,it does work

------------------ 原始邮件 ------------------ 发件人: "groovy/GMavenPlus" @.>; 发送时间: 2022年7月1日(星期五) 晚上11:33 @.>; @.**@.>; 主题: Re: [groovy/GMavenPlus] Unrecognized target bytecode: '8' (Issue #223)

I can't find the source code for it, but it looks like the synonyms are what you'd expect (https://docs.oracle.com/en/java/javase/11/tools/javac.html#GUID-AEEC9F07-CB49-4E96-8BC7-BCC2C7F725C9). I'll add these.

In the mean time, it works for me with the below XML <properties> <skipBytecodeCheck>true</skipBytecodeCheck> </properties>

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

xiumin1993 commented 2 years ago

yeah,After check plugin source code ,I already change to this

发自我的iPhone

------------------ Original ------------------ From: Keegan Witt @.> Date: Fri,Jul 1,2022 11:45 PM To: groovy/GMavenPlus @.> Cc: xiumin1993 @.>, Author @.> Subject: Re: [groovy/GMavenPlus] Unrecognized target bytecode: '8' (Issue#223)

Actually, I'm remembering why I implemented it this way now. It's because while javac accepts both 1.8 and 8, Groovy does not. See https://github.com/apache/groovy/blob/38c85f371128b6bc46ba952228640d433b1c799e/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java

I suggest either <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>

Since this would be equivalent and works for both javac and groovyc, or <targetBytecode>1.8</targetBytecode>

The second of these can be placed in <properties> or in the <configuration> of GMavenPlus or one of its <execution>s.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

keeganwitt commented 2 years ago

I'm thinking about whether to translate the synonym to make this easier. I want to be careful I'm not breaking something else I haven't thought of.

https://github.com/groovy/GMavenPlus/pull/224

xiumin1993 commented 2 years ago

Add the synonym , like 1.8||8,then test it with right Java version and maven config  If it works normal  I think it's ok

发自我的iPhone

------------------ Original ------------------ From: Keegan Witt @.> Date: Sat,Jul 2,2022 0:08 AM To: groovy/GMavenPlus @.> Cc: xiumin1993 @.>, Author @.> Subject: Re: [groovy/GMavenPlus] Unrecognized target bytecode: '8' (Issue#223)

I'm thinking about whether to translate the synonym to make this easier. I want to be careful I'm not breaking something else I haven't thought of.

224

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

keeganwitt commented 2 years ago

I was more worried about if there was other JDK vendors (like Azul Zulu, Amazon Corretto, Alibaba Dragonwell, IBM, etc) that have other strings they accept that I haven't accounted for. I'm pretty confident this will work with Eclipse Adoptium and Oracle JDK.

keeganwitt commented 2 years ago

I suppose if more cases come up, we can deal with them at that time. This seems reasonable to proceed with for now.

keeganwitt commented 2 years ago

I released 2.0.0-SNAPSHOT with this change. As an additional verification, it'd be helpful to confirm this resolves your issue. You can get that from here

<repository>
  <id>sonatype-oss-snapshots</id>
  <url>https://oss.sonatype.org/content/repositories/snapshots</url>
  <releases>
    <enabled>false</enabled>
  </releases>
  <snapshots>
    <enabled>true</enabled>
    <updatePolicy>always</updatePolicy>
    <checksumPolicy>warn</checksumPolicy>
  </snapshots>
</repository>
xiumin1993 commented 2 years ago

I think the best solustion is add a note on the exception message that they can use skipBytecodeCheck=true to skip this check when they get the same exception with me, also clearly descripe the exception message “Unrecognized target bytecode: '8'” not clear enough

发件人: Keegan Witt 发送时间: 2022年7月2日 1:41 收件人: groovy/GMavenPlus 抄送: xiumin1993; Author 主题: Re: [groovy/GMavenPlus] Unrecognized target bytecode: '8' (Issue#223)

I suppose if more cases come up, we can deal with them at that time. This seems reasonable to proceed with for now. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>