Skip to content

Conversation

@wrprice
Copy link
Contributor

@wrprice wrprice commented Sep 7, 2025

In multi-project Gradle builds where one project depends on another project, for example:

implementation project(':otherProject')

The dependency is represented in the Gradle API as a ProjectDependency object, but ProjectDependency::getDependencyProject was deprecated, and then removed in Gradle 9.0.0. When using Gradle >= 9, it now requires two steps to resolve target of the dependency:

  1. Use reflection to access ProjectDependency::getPath (added in Gradle 8.11)
  2. Resolve the target project using Project::findProject(String path)

fixes #8764


^Add meaningful description above

Click to collapse/expand PR instructions

By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -

  • are all your own work, and you have the right to contribute them.
  • are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).

Please make sure (eg. git log) that all commits have a valid name and email address for you in the Author field.

If you're a first time contributor, see the Contributing guidelines for more information.

If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.

PR approval and merge checklist:

  1. Was this PR correctly labeled, did the right tests run? When did they run?
  2. Is this PR squashed?
  3. Are author name / email address correct? Are co-authors correctly listed? Do the commit messages need updates?
  4. Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?

If this PR targets the delivery branch: don't merge. (full wiki article)

@mbien mbien added Gradle [ci] enable "build tools" tests ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Sep 7, 2025
Comment on lines +1567 to +1581
Function<ProjectDependency, Project> projDependencyToProject =
sinceGradleOrDefault(
"9.0",
() -> {
Method getPath = ProjectDependency.class.getMethod("getPath");
return dep -> {
try {
String path = (String) getPath.invoke(dep);
return project.findProject(path);
} catch (ReflectiveOperationException e) {
throw new UnsupportedOperationException(e);
}
};
},
() -> ProjectDependency::getDependencyProject); // removed in Gradle 9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO: this would be more future proof if we would call the new method directly and use reflection for the removed method. (basically the other way around)

@lkishalmi @sdedic do you think we can bump the gradle tooling version of this module so that we can call getPath() directly?

Copy link
Contributor Author

@wrprice wrprice Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gradle >= 8.11 but <9 should have both APIs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an alternative branch where I think I've done the necessary work to bump this module up to Gradle 8.11.1. Tested locally on some personal Gradle projects using 7.5.x, 8.11-14, and 9.0.0 and they all open w/out error notifications. In the process there was a fun roadbump that turns out to be a JDK bug re: method references under certain conditions.

The 8.11.1 upgrade has several more required changes compared to this spot fix. LMK how you'd like me to proceed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wrprice sounds great! We could try to get this PR here in first, then see if we can bump the tooling version.

Last time I tried I could get a hello world project using gradle 5.x to build, but I believe 4 didn't work anymore. But I personally don't use gradle all that much, I let others comment on the versions question. NB generally tries to support lower versions if it is still reasonably maintainable while keeping up with latest releases.

The 8.11.1 upgrade has several more required changes compared to this spot fix. LMK how you'd like me to proceed.

Once this PR here is merged, we could certainly take a look at the version bump proposal, unless there is a showstopper I am not aware of (cc @lkishalmi )

@mbien mbien added this to the NB28 milestone Sep 7, 2025
@mbien
Copy link
Member

mbien commented Sep 10, 2025

looks like the paperwork check doesn't like the commit header. The reason for that is because github added the noreply mail which isn't a valid address. Its a github settings.

Assuming your local git log has the right email address on the commit, you will likely still have to make a change to this PR for the new setting to take effect. Feel free to do a git pull --rebase https://github.com/apache/netbeans master and then simply force push into your branch.

You can see if it is worked by looking at the patch file for this PR:

https://github.com/apache/netbeans/pull/8797.patch

@wrprice wrprice marked this pull request as ready for review September 10, 2025 03:51
Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes look good to me, CI is happy too

@mbien mbien merged commit d10bf81 into apache:master Sep 10, 2025
32 checks passed
@mbien
Copy link
Member

mbien commented Sep 10, 2025

@wrprice thanks for the fix and congrats on your first contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) Gradle [ci] enable "build tools" tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NetBeans 27 gives error with Gradle 9 web project

2 participants