Subject: [pgjdbc/pgjdbc] PR #3607: Copr: Use Java 21 as the build dependency

From: "mkoncek (@mkoncek)" <[email-masked]>
Date: Wed, 16 Apr 2025 06:32:35 +0000

Fixes: #3591

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing](https://github.com/pgjdbc/pgjdbc/blob/master/CONTRIBUTING.md) document?
* [ ] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change?

<!-- You can erase any parts of this template not applicable to your Pull Request. -->

### New Feature Submissions:

1. [ ] Does your submission pass tests?
2. [ ] Does `./gradlew styleCheck` pass ?
3. [ ] Have you added your new test classes to an existing test suite in alphabetical order?

### Changes to Existing Features:

* [ ] Does this break existing behaviour? If so please explain.
* [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
* [ ] Have you written new tests for your core changes, as applicable?
* [ ] Have you successfully run tests with your changes locally?

---

From: "mkoncek (@mkoncek)" <[email-masked]>
Date: Thu, 17 Apr 2025 07:52:29 +0000

As this is not a code change, i did not execute any build locally.

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Thu, 17 Apr 2025 10:31:14 +0000

> As this is not a code change, i did not execute any build locally.

is that why it is failing ?

---

From: "mkoncek (@mkoncek)" <[email-masked]>
Date: Thu, 17 Apr 2025 11:28:25 +0000

> is that why it is failing ?

I am 99 % sure, though I am not the person who set Copr builds up. It is consistent with the logs, `java-17-openjdk-devel` is installed before the build itself, so it must be configured from here.

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Thu, 17 Apr 2025 12:24:14 +0000

It does not seem to fix the failure

---

From: "mkoncek (@mkoncek)" <[email-masked]>
Date: Thu, 17 Apr 2025 18:04:16 +0000

Yeah, I noticed that. My only guess is that the Copr build uses these settings from the master branch, not from PRs.
if you look at [this log](https://download.copr.fedorainfracloud.org/results/@pgjdbc/pgjdbc-ci/srpm-builds/08909844/builder-live.log.gz) and the line:
```
 'source_json': {'builddeps': 'git java-17-openjdk-devel python-unversioned-command',
```
that is exactly the content of the file that I am changing in this PR and that is what fails during the Copr build:
```
INFO: installing package(s): git java-17-openjdk-devel python-unversioned-command
Updating and loading repositories:
 updates                                100% | 778.3 KiB/s |  25.7 KiB |  00m00s
 fedora                                 100% | 314.5 KiB/s |  28.0 KiB |  00m00s
Repositories loaded.
Failed to resolve the transaction:
No match for argument: java-17-openjdk-devel
You can try to add to command line:
  --skip-unavailable to skip unavailable packages
WARNING: DNF5 command failed, retrying, attempt #2, sleeping 10s
```

---

From: "mkoncek (@mkoncek)" <[email-masked]>
Date: Mon, 28 Apr 2025 13:15:42 +0000

Now Copr build fails because the Gradle build somehow only accepts Java 17:
```
A problem occurred configuring project ':postgresql'.
> Failed to query the value of task ':postgresql:compileJava' property 'options.release'.
   > Failed to calculate the value of task ':postgresql:compileJava' property 'javaCompiler'.
      > Cannot find a Java installation on your machine (Linux 6.11.8-300.fc41.x86_64 amd64) matching: {languageVersion=17, vendor=any vendor, implementation=vendor-specific}. Toolchain download repositories have not been configured.
```

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Mon, 28 Apr 2025 13:32:05 +0000

@mkoncek , we do use Java 17 by default, however, there's an option to adjust it: `./gradlew .. -PjdkBuildVersion=21 ...`
Could you give it a try?

It might be time to go for Java 21 by default for the build though.

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Mon, 28 Apr 2025 14:56:46 +0000

This is funny and not so funny at the same time:

```
* What went wrong:
Execution failed for task ':postgresql:compileJava'.
> Compilation failed; see the compiler output below.
  warning: [options] source value 8 is obsolete and will be removed in a future release
  warning: [options] target value 8 is obsolete and will be removed in a future release
  warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
  error: warnings found and -Werror specified
```

@mkoncek , could you add the following as well?

```diff
--- a/build-logic/jvm/src/main/kotlin/build-logic.java.gradle.kts
+++ b/build-logic/jvm/src/main/kotlin/build-logic.java.gradle.kts
@@ -62,6 +62,11 @@ tasks.configureEach<JavaCompile> {
                 }
             }
         )
+        if (buildParameters.jdkBuildVersion >= 21 && buildParameters.targetJavaVersion < 11) {
+            // We know target Java 8 is deprecated with Java 21, so silence the warning
+            // otherwise the build fails due to -Werror below
+            compilerArgs.add("-Xlint:-options")
+        }
         if (!buildParameters.enableCheckerframework) {
             compilerArgs.add("-Xlint:deprecation")
         } else {
```

---

From: "mkoncek (@mkoncek)" <[email-masked]>
Date: Tue, 29 Apr 2025 07:11:02 +0000

Sure.

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Tue, 29 Apr 2025 11:19:13 +0000

Wow. So much fun. It finally worked!