groovy / GMavenPlus

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

Groovy 2.4.18 and later supports targetBytecode but GMavenPlus does not allow it #256

Closed samrocketman closed 1 year ago

samrocketman commented 1 year ago

This is a bug report for gmaven plus.

Groovy 2.4.18 release notes https://groovy-lang.org/changelogs/changelog-2.4.18.html

I have verified with other Groovy compiler plugins that targeting OpenJDK 11 bytecode works.

samrocketman commented 1 year ago

Correction

Correction on verification. I avoided maven just to be sure and this is what I determined. I will close this as a result.

Verification steps

cat > Hello.groovy <<'EOF'
class Hello {
}
EOF

./groovy-2.4.21/bin/groovyc -Jtarget=11 -Jsource=11 Hello.groovy

javap -verbose Hello.class | grep 'major\|minor'

javap results in

  minor version: 0
  major version: 49

According to stack overflow:

major minor Java platform version
45 3 1.0
45 3 1.1
46 0 1.2
47 0 1.3
48 0 1.4
49 0 1.5
50 0 1.6
51 0 1.7
52 0 1.8
53 0 9
54 0 10
55 0 11
56 0 12
57 0 13
58 0 14
59 0 15
60 0 16
61 0 17
62 0 18
63 0 19
samrocketman commented 1 year ago

Looks like allowed JDKs is up to bytecode 1.8 but I can't get groovyc to output anything other than bytecode 1.5.

./groovy-2.4.21/bin/groovyc -J groovy.target.indy=1 -J groovy.target.bytecode=1.8 Hello.groovy

javap still returns major 49.

samrocketman commented 1 year ago

I'll leave this open for a short period in case someone else more experienced in Groovy can correct me.

samrocketman commented 1 year ago

Can target newer bytecode via maven property

Okay, never mind. I was able to target newer bytecodes in maven and it actually works.

<properties>
  <groovy.target.bytecode>1.8</groovy.target.bytecode>
</properties>
$ javap -verbose target/classes/net/gleske/scmfilter/credential/GraphQLTokenCredential.class | grep 'major\|minor'
  minor version: 0
  major version: 52
samrocketman commented 1 year ago
<properties>
  <maven.compiler.source>11</maven.compiler.source>
  <maven.compiler.target>11</maven.compiler.target>
</properties>

Results in a compile error for Groovy 2.4.21. This makes sense because Groovy 2.4.21 only handles bytecode up to 8.

Switching to Java 8 or 1.8 works for gmavenplus.

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

Closing bug report as not a bug

At first I misunderstood what I was doing versus what I wanted. I was able to verify there is no bug and how to check my assumptions.

I documented my process in case anybody else finds it useful.

keeganwitt commented 1 year ago

targetBytecode is what controls this. It defaults to maven.compiler.target as you have noticed. Using that default ensures the bytecode version GMavenPlus output matches classes output by the Maven Compiler plugin (e.g. any Java files you have).

I'm glad you were able to get it working!

samrocketman commented 1 year ago

Thanks for the info; and yeah I was a bit verbose but I figured details would help someone else in my position so I tried to be clear about my method (for verifying and not just assuming the setting worked or didn't).