Cannot import gradle 7.0 project that uses javax.annotation
When importing a project that has a dependency to
implementation 'javax.annotation:javax.annotation-api:1.3.2'
an import like:
import javax.annotation.PostConstruct;
will lead to an error:
The package javax.annotation is accessible from more than one module: <unnamed>, java.annotation
but only if the project uses gradle 7.0. (Gradle 7.0-rc-1 was used).
When downgrading to gradle 6.8.3 and executing "Refresh Gradle Project" the error goes away.
When removing
Expected Behavior
Project should be imported without errors.
Current Behavior
Project shows error after importing.
Context
Trying to upgrade our project to gradle 7.0 to be able to use Java 16. Upgrading to 6.7 or higher (and using toolchains) is not an option because of https://github.com/eclipse/buildship/issues/1035.
Steps to Reproduce
Extract the project, import into eclipse.
Your Environment
Eclipse IDE for Java Developers (includes Incubating components) Version: 2021-03 (4.19.0) Build id: 20210312-0638 Buildship: Eclipse Plug-ins for Gradle 3.1.5.v20210302-1324-s org.eclipse.buildship.feature.group Eclipse Buildship
I can confirm I'm having the exact same problem. Using Gradle 7.0-rc-2
I can confirm the issue still exists with the final release of Gradle 7.0 too.
Gradle 7 enables JPMS by default, so, that may be the relevant difference. If that is the case, enabling JPMS with Gradle 6 should reproduce the problem.
Thanks for the tip. I can now work around the issue. Here's what I can report: If I add modularity.inferModulePath = true to a Gradle 6.8.x project, as suspected we can reproduce the issue. And, sure enough, if I add modularity.inferModulePath = false to a Gradle 7.0 project I no longer encounter the issue.
Thank you, @james-bryant for the workaround. WIth this is I can import the project into eclipse. Unfortunately Issue #1035 then kicks in...
I have a similar issue in my project after upgrading Gradle from 6.8.3 to 7.0.
Diff: https://github.com/itsallcode/white-rabbit/compare/64765a8e69016e99a00a9e3c49831eb3b6b19f89..b3057e4f13ccf238624e759f71584e3ba94dba25
Before the change, there where no compile errors in Eclipse. After the upgrade I get error The type com.sun.javafx.application.ParametersImpl is not accessible in class JavaFxAppUiTestBase.
The proposed workaround of adding modularity.inferModulePath = false worked, see
https://github.com/itsallcode/white-rabbit/commit/c3c4e31b0cdd679c6a834c34418cc6ab60fc1d9b
We have encountered this issue as well with Gradle 7.0 and buildship integration in Eclipse.
I think that this issue was resolved in gradle version 7.0.1. See https://github.com/gradle/gradle/issues/16922
We will upgrade gradle to newest version and get back with the result.
We have encountered this issue as well with Gradle 7.0 and buildship integration in Eclipse.
I think that this issue was resolved in gradle version 7.0.1. See gradle/gradle#16922
We will upgrade gradle to newest version and get back with the result.
I can now attest that upgrading gradle to version 7.4.2 solves this issue.
I think that this issue can be closed.