Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that spring-boot-starter-parent sets maven.compiler.release and how to unset it if needed #37993

Closed
brucelwl opened this issue Oct 23, 2023 · 9 comments
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@brucelwl
Copy link

springboot 3.2.0-RC1

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgs>
            <arg>--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED</arg>
            <arg>--add-exports=java.base/jdk.internal.vm=ALL-UNNAMED</arg>
        </compilerArgs>
    </configuration>
</plugin>

the default property <maven.compiler.release>${java.version}</maven.compiler.release>

cause error

exporting a package from system module java.base is not allowed with --release

see
image

source plexus-compiler-javac-2.13.0.jar

image

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 23, 2023
@wilkinsona
Copy link
Member

Thanks for trying to RC. Have you only just started seeing this problem? We started setting maven.compiler.release in 3.1.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Oct 23, 2023
@brucelwl
Copy link
Author

brucelwl commented Oct 23, 2023

I previously discovered this PR #34365, but it still caused my program to not compile properly, and currently I have not found a corresponding solution
image

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 23, 2023
@wilkinsona
Copy link
Member

Yes, I suspect that #34365 introduced the problem. However, if that is the case, this would also fail with Spring Boot 3.1. Does it?

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Oct 23, 2023
@brucelwl
Copy link
Author

@wilkinsona I tried using Spring Boot version 3.1 and found the same problem

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 23, 2023
@wilkinsona wilkinsona added status: waiting-for-triage An issue we've not yet triaged and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Oct 23, 2023
@wilkinsona
Copy link
Member

Thanks.

You can undo spring-boot-starter-parent setting maven.compiler.release by setting it to an empty string:

<maven.compiler.release></maven.compiler.release>

You then have to configure the source and target instead:

<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

With these three properties in place, a project that uses --add-exports should work.

We'll have to decide if we want to continue to set maven.compiler.release or switch back to source and target.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Oct 23, 2023
@brucelwl
Copy link
Author

Thank you very much. <maven.compiler.release/> has solved my problem

@wilkinsona wilkinsona changed the title exporting a package from system module java.base is not allowed with --release Configuration of maven.compiler.release in spring-boot-starter-parent prevents the use of --add-exports compiler argument Oct 23, 2023
@mhalbritter
Copy link
Contributor

We'll have to decide if we want to continue to set maven.compiler.release or switch back to source and target.

Upside of release is that the compiler then checks if you're using an API from a newer JDK, which is a definitive pro. Do we know why the JDK developers prohibit opening modules when using --release but allowing it when using --target and --source?

@wilkinsona
Copy link
Member

Upside of release is that the compiler then checks if you're using an API from a newer JDK, which is a definitive pro

It's definitely a good thing if you're building with a JDK version other than the one with which you'll run your app. However, if the two match, that benefit disappears and I wonder how common it is for them not to match.

Do we know why the JDK developers prohibit opening modules when using --release but allowing it when using --target and --source?

I don't.

@philwebb philwebb changed the title Configuration of maven.compiler.release in spring-boot-starter-parent prevents the use of --add-exports compiler argument Configuration of maven.compiler.release in spring-boot-starter-parent prevents the use of '--add-exports' compiler argument Oct 24, 2023
@wilkinsona
Copy link
Member

We're going to document that we set maven.compiler.release by default and how and when to unset it. The JEP describes when. It's if you want to use --add-exports, --add-reads, or --patch-module to modify system modules.

@wilkinsona wilkinsona changed the title Configuration of maven.compiler.release in spring-boot-starter-parent prevents the use of '--add-exports' compiler argument Document that spring-boot-starter-parent sets maven.compiler.release and how to unset it if needed Oct 25, 2023
@wilkinsona wilkinsona added type: documentation A documentation update and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Oct 25, 2023
@wilkinsona wilkinsona added this to the 3.1.x milestone Oct 25, 2023
@mhalbritter mhalbritter self-assigned this Oct 27, 2023
@mhalbritter mhalbritter modified the milestones: 3.1.x, 3.1.6 Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

4 participants