Skip to content

Commit

Permalink
Merge pull request #232 from groovy/support_jdk20
Browse files Browse the repository at this point in the history
Support Java 20 bytecode
  • Loading branch information
keeganwitt authored Oct 20, 2022
2 parents 8a195c3 + 70cc954 commit 3c8024b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
*/
public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {

/**
* Groovy 4.0.6 version.
*/
protected static final Version GROOVY_4_0_6 = new Version(4, 0, 6);

/**
* Groovy 4.0.2 version.
*/
Expand Down Expand Up @@ -195,6 +200,8 @@ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {
* Using 16 requires Groovy >= 3.0.6.
* Using 17 requires Groovy >= 3.0.8 or Groovy > 4.0.0-alpha-3.
* Using 18 requires Groovy > 4.0.0-beta-1.
* Using 19 requires Groovy > 4.0.2.
* Using 20 requires Groovy > 4.0.6.
*/
@Parameter(property = "maven.compiler.target", defaultValue = "1.8")
protected String targetBytecode;
Expand Down Expand Up @@ -483,7 +490,11 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
* org.codehaus.groovy.classgen.asm.WriterController.
*/
protected void verifyGroovyVersionSupportsTargetBytecode() {
if ("19".equals(targetBytecode)) {
if ("20".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_6)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_6 + " or newer.");
}
} else if ("19".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_2)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_2 + " or newer.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
*/
public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSourcesMojo {

/**
* Groovy 4.0.6 version.
*/
protected static final Version GROOVY_4_0_6 = new Version(4, 0, 6);

/**
* Groovy 4.0.2 version.
*/
Expand Down Expand Up @@ -198,6 +203,8 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource
* Using 16 requires Groovy >= 3.0.6.
* Using 17 requires Groovy >= 3.0.8 or Groovy > 4.0.0-alpha-3.
* Using 18 requires Groovy > 4.0.0-beta-1.
* Using 19 requires Groovy > 4.0.2.
* Using 20 requires Groovy > 4.0.6.
*
* @since 1.0-beta-3
*/
Expand Down Expand Up @@ -410,7 +417,11 @@ protected void resetStubModifiedDates(final Set<File> stubs) {
* org.codehaus.groovy.classgen.asm.WriterController.
*/
protected void verifyGroovyVersionSupportsTargetBytecode() {
if ("19".equals(targetBytecode)) {
if ("20".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_6)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_6 + " or newer.");
}
} else if ("19".equals(targetBytecode)) {
if (groovyOlderThan(GROOVY_4_0_2)) {
throw new IllegalArgumentException("Target bytecode " + targetBytecode + " requires Groovy " + GROOVY_4_0_2 + " or newer.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,20 @@ public void testJava19WithSupportedGroovy() {
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testJava20WithUnsupportedGroovy() {
testMojo = new TestMojo("4.0.5");
testMojo.targetBytecode = "20";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test
public void testJava20WithSupportedGroovy() {
testMojo = new TestMojo("4.0.6");
testMojo.targetBytecode = "20";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testUnrecognizedJava() {
testMojo = new TestMojo("2.1.2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,20 @@ public void testJava19WithSupportedGroovy() {
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testJava20WithUnsupportedGroovy() {
testMojo = new TestMojo("4.0.5");
testMojo.targetBytecode = "20";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test
public void testJava20WithSupportedGroovy() {
testMojo = new TestMojo("4.0.6");
testMojo.targetBytecode = "20";
testMojo.verifyGroovyVersionSupportsTargetBytecode();
}

@Test(expected = IllegalArgumentException.class)
public void testUnrecognizedJava() {
testMojo = new TestMojo("2.1.2");
Expand Down

0 comments on commit 3c8024b

Please sign in to comment.