tada / pljava

PL/Java is a free add-on module that brings Java™ Stored Procedures, Triggers, Functions, Aggregates, Operators, Types, etc., to the PostgreSQL™ backend.
http://tada.github.io/pljava/
Other
242 stars 77 forks source link

Cannot specify java release other an '9' for maven-compiler-plugin #403

Closed udesaiitrs closed 1 year ago

udesaiitrs commented 2 years ago

I noticed that the maven-compiler-plugin does not take any java release other than '9'. Digging deeper I saw that this is hardcoded in org.postgresql.pljava.annotation.processing.DDRProcessor. Is this something that can be changed/updated to a newer Java version, i.e. 17?

jcflack commented 2 years ago

Can you be more specific about exactly what you are trying to do and what difficulty you encounter?

PL/Java's own code sticks to release 9 features so that PL/Java itself can be built on any Java release back to 9. I routinely test it on later releases including 17, and your user code that you run with PL./Java can use the features of whatever Java release you compile it with and have pljava.libjvm_location pointing to at runtime.

When you compile your user code against the PL/Java API jar, you may see this warning:

warning: Supported source version 'RELEASE_9' from annotation processor 'org.postgresql.pljava.annotation.processing.DDRProcessor' less than -source '17'

But that does not stop you from compiling or using your code.

I just wrote this test class that uses a Java 17 feature (sealed classes):

import org.postgresql.pljava.annotation.Function;

public abstract sealed class Foo {
  public final class A extends Foo {
  }
  @Function
  public static String foo() { return "Hello, world!"; }
}

I compiled it using javac from the command line, and got the warning, but there was no other difficulty. I did not write a POM for it and try Maven, but does that not produce a similar result?

udesaiitrs commented 2 years ago

Hi, yes I am seeing now that we have a 'fail-on-warning' clause for our custom extension code. I tried changing this plugin configuration to use release version 17 like so:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <release>17</release>
        </configuration>
      </plugin>

Does this need to stay set to 9 always?

You're correct I've already updated the JRE used to openjdk-17 and all is working correctly.

jcflack commented 2 years ago

If you set release to 9 when compiling your own code, you will limit your own code to Java 9 features, which seems unnecessary.

If it were not for the fail-on-warning clause, there would not be any difficulty.

The source version being warned about is simply the Java source version that PL/Java's annotation processor is coded to. Because the PL/Java annotations don't involve any Java source code features later than Java 9, there hasn't been any need to declare a later source version.

I have avoided doing something more complicated (like trying to find the compiler version at run time and "declare" that source version in the annotation processor), because that would essentially be claiming that the processor understands constructs it was never coded to understand.

udesaiitrs commented 2 years ago

Got it, that makes sense thanks. I will go with disabling the fail-on-warning setting for now, that logic makes sense. Thanks!

jcflack commented 2 years ago

I have pushed a branch bug/REL1_6_STABLE/issue403 that should allow you to build with the fail-on-warning option, if you'd be interested in testing that.

udesaiitrs commented 2 years ago

Yes, I've tested this locally with the stricter compiler configuration and no fail-on-warning setting and all works fine with java 17 release set for the compiler configuration. Thanks, we'll keep a lookout for the next release.

jcflack commented 1 year ago

Reopening so I can have the satisfaction of closing.

jcflack commented 1 year ago

Believed resolved in 1.6.5.