Gradle Parameter Replacement incompatible with Gradle Version
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Apache NetBeans version
Apache NetBeans 22
### What happened
NetBeans seems to replace Gradle CLI Parameters with their short form based on [GradleCommandLine](https://github.com/apache/netbeans/blob/master/extide/gradle/src/org/netbeans/modules/gradle/api/execute/GradleCommandLine.java#L146). When defining a custom build task with the `--refresh-dependency` flag, this is shortened to `-U`. The addition of the `-U` flag to NetBeans came with commit 9bc649bac0bdd83d51a71cce80759252dd213b00. This flag is not supported in Gradle versions below 8:
* [Gradle 7.6.2 Userguide](https://docs.gradle.org/7.6.2/userguide/command_line_interface.html) (note that `-U` is missing from the `--refresh-dependencies` documentation
* [Gradle 8.5 Userguide](https://docs.gradle.org/8.5/userguide/command_line_interface.html) (here `-U` is documented)
Here is the Gradle commit that added the short form for `--refresh-dependencies`: https://github.com/gradle/gradle/commit/3c0d26f9cb468cec7db41528daae90c1876120e6. This is only included in 8.* releases.
This behavior breaks all custom Gradle tasks using the `--refresh-dependencies` flag in projects that use a Gradle wrapper < 8.
### Language / Project Type / NetBeans Component
Java Gradle Project
### How to reproduce
* Create a Gradle Project with a Gradle 7 wrapper (`gradle init`, then `./gradlew wrapper --gradle-version 7.6.2`). Now `./gradlew -U` should fail with `Unknown command-line option '-U'.`
* Add a custom task under `Project Properties` -> `Build` -> `Build Actions`, with the arguments `--refresh-dependencies check`
* Execute the new task
* The Output shows something like this:
```
JAVA_HOME="/usr/lib/jvm/default"
cd ; ./gradlew --configure-on-demand -U check
```
Here `--refresh-dependencies` has been replaced with `-U` which is not supported by the Gradle wrapper.
* The output stays empty and an unexpected exception is reported:
```
A org.gradle.tooling.exceptions.UnsupportedBuildArgumentException has occurred.
If you are running the [latest](https://netbeans.apache.org/download) version of NetBeans you can [report this](https://netbeans.apache.org/nb/report-issue), including a copy of your messages.log file as an attachment.
The messages.log file is located in [this folder](file:///home/me/.netbeans/22/var/log/).
```
Here is the `messages.log` file: [messages.log](https://github.com/user-attachments/files/15613174/messages.log)
### Did this work correctly in an earlier version?
Apache NetBeans 21
### Operating System
Linux
### JDK
openjdk 17.0.11 2024-04-16
### Apache NetBeans packaging
Third-party package
### Anything else
This should have worked even on NetBeans 22 before the commit 9bc649bac0bdd83d51a71cce80759252dd213b00.
This might also affect other Gradle flags, I only noticed it for `--refresh-dependencies` until now.
I would suggest not replacing user supplied arguments or to keep track of the minimum required Gradle version for each flag and only replace flags that are actually supported.
I'm using the [`netbeans-bin` AUR package](https://aur.archlinux.org/packages/netbeans-bin) which uses the Release zip from https://downloads.apache.org/netbeans/netbeans/22/netbeans-22-bin.zip but this bug is also reproducible in Ubuntu and shouldn't depend on the packaging.
### Are you willing to submit a pull request?
No
Contributor guide
Research direction
Start in extide/gradle/src/org/netbeans/modules/gradle/api/execute/GradleCommandLine.java at the parameter replacement logic referenced in the report. Reproduce the custom Build Action with a Gradle 7.6.2 wrapper and `--refresh-dependencies`; done means the action runs without converting this unsupported short option and preserves compatibility with older Gradle versions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100