Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrecognized target bytecode: '8' #223

Closed
xiumin1993 opened this issue Jul 1, 2022 · 13 comments
Closed

Unrecognized target bytecode: '8' #223

xiumin1993 opened this issue Jul 1, 2022 · 13 comments
Assignees
Milestone

Comments

@xiumin1993
Copy link

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
Copy link
Member

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
Copy link
Member

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

@xiumin1993
Copy link
Author

xiumin1993 commented Jul 1, 2022 via email

@keeganwitt
Copy link
Member

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
Copy link
Member

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
Copy link
Author

xiumin1993 commented Jul 1, 2022 via email

@xiumin1993
Copy link
Author

xiumin1993 commented Jul 1, 2022 via email

@keeganwitt
Copy link
Member

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

@keeganwitt keeganwitt self-assigned this Jul 1, 2022
@keeganwitt keeganwitt added this to the 1.14.0 milestone Jul 1, 2022
@xiumin1993
Copy link
Author

xiumin1993 commented Jul 1, 2022 via email

@keeganwitt
Copy link
Member

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
Copy link
Member

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

keeganwitt added a commit that referenced this issue Jul 1, 2022
Support bytecode 5, 6, 7, 8, and 1.9 args (closes #223)
@keeganwitt
Copy link
Member

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
Copy link
Author

xiumin1993 commented Jul 2, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants