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

Add -proc:full to javac args for plugins #811

Closed
jglick opened this issue Jul 31, 2023 · 2 comments · Fixed by #814 or jenkinsci/pom#469
Closed

Add -proc:full to javac args for plugins #811

jglick opened this issue Jul 31, 2023 · 2 comments · Fixed by #814 or jenkinsci/pom#469

Comments

@jglick
Copy link
Member

jglick commented Jul 31, 2023

At least plugin builds, and probably some other component builds such as core (maybe just do this also in the generic parent POM), should be given the -proc:full argument when this is available (21+?). Otherwise builds may be broken in some future Java version (22?) due to JDK-8306819. See openjdk/jdk#14499 by @jddarcy.

There is some discussion of a bare -proc argument in older versions but I do not see this in the JDK 11 help; it does not appear that there is any argument which can be passed to JDK 11 which will prevent the build from breaking in the future, which seems unfortunate as it would mean that we would need to detect the JDK version with a profile to support building with newer JDKs even when targeting 11 or 17.

Switching to an explicit list of annotation processors would be awkward since there are a bunch of them in the Maven classpath and we do rely on the service detection to run them all. (In fact there is at least one proprietary plugin in CloudBees CI which adds its own, under the expectation that plugins depending on it will automatically run that processor.)

@jddarcy
Copy link

jddarcy commented Jul 31, 2023

Hello,

Yes, the -proc:full option will be supported in JDK 21 and later. (It is technically possible to backport support for it -- it implements the current default javac policy for annotation processing -- but there are currently no plans to do so.)

To be explicit as it what is likely to change in the future, it is the implicit running of annotation processors out of the class path without any annotation processing configuration options. For example, without using -proc:full, the change in behavior could also be averted by setting -processorpath (even if -processorpath is set to the same value as the class path). Switching to a list of processors to run is one way to avoid the the change in behavior, but is not the only way and not required.

Quoting the new javac note:

Annotation processing is enabled because one or more processors were
found on the class path. A future release of javac may disable
annotation processing unless at least one processor is specified by
name (-processor), or a search path is specified (--processor-path,
--processor-module-path), or annotation processing is enabled
explicitly (-proc:only, -proc:full).
Use -Xlint:-options to suppress this message.
Use -proc:none to disable annotation processing.

If you see this note from a JDK 21 or 22 build in a project's build logs, it is subject to the future policy change without changing the options in one of the listed ways.

To change the configuration of a JDK 17u or 11u build to future proof it against the policy change, I'd recommend setting processorpath (or --processor-module-path), which would work on all the releases in question.

HTH

@jglick
Copy link
Member Author

jglick commented Jul 31, 2023

Thanks for the detailed note @jddarcy!

it is the implicit running of annotation processors out of the class path without any annotation processing configuration options

Exactly, this is what the Jenkins project relies on. (So does NetBeans, even more heavily.)

It does not look like the Maven plugin currently supports this workaround: https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#annotationprocessorpaths says

If specified, the compiler will detect annotation processors only in those classpath elements. If omitted, the default classpath is used to detect annotation processors.

What would be needed would be a mojo option that sets -processorpath to the same value as -classpath. That would not be great anyway, since there are already complicated tricks to let -classpath scale well to very large values on different operating systems, and doubling the command length would make mvn -X output even more unwieldy. Conditionally adding -proc:full on Java 21+ sounds easier and cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants