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

[MPOM-453] Disable annotation processing by compiler #157

Merged
merged 3 commits into from
Jan 27, 2024

Conversation

slawekjaranowski
Copy link
Member

No description provided.

@cstamas
Copy link
Member

cstamas commented Jan 14, 2024

This can be a problem, as no way to override this later (only in java 20? "full"?) @bmarwell will tell 😄

@slawekjaranowski
Copy link
Member Author

We use sisu-maven-plugin for generating list of components, so should be ok.

@cstamas
Copy link
Member

cstamas commented Jan 15, 2024

With a grain of salt... I'd rather define compiler.proc=none property and allow that property to be changed, than this. As if project DOES need annotation processing, and is below Java 21 (see https://bugs.openjdk.org/browse/JDK-8309870) then there is no way to override it.

@kwin
Copy link
Member

kwin commented Jan 15, 2024

I think it is best practice to only enable annotation processors by their fully qualified class name. This is possible by setting https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#annotationProcessors. This should IMHO take precedence (but I haven’t checked) over proc being none.

@slawekjaranowski
Copy link
Member Author

I need more tests ... like possibility to override

@slawekjaranowski slawekjaranowski marked this pull request as draft January 16, 2024 09:08
@bmarwell
Copy link
Contributor

We could introduce a property, eg maven.compiler.apt.default or similar. Easy to override per project via .mvn/jvm.options.

I think the way to go is to introduce a new default lifecycle in the compiler plugin in both the compile and test compile Mojos.

This means running a new execution default-process in generate-sources with -proc:only and running a new execution default-test-process in generate-test-sources.

I do this in all of my projects like this.

However, not sure how incremental works with this proposal.

@slawekjaranowski
Copy link
Member Author

  • m-compiler-p proc parameter doesn't have a property
  • we can use property which can be overridded by empty value, to achieve default behavior, in child project

@slawekjaranowski slawekjaranowski marked this pull request as ready for review January 20, 2024 11:17
Copy link
Contributor

@bmarwell bmarwell left a comment

Choose a reason for hiding this comment

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

Works for me as of now. Maybe we can look into a project using an annotation processor to make use of the two phases I mentioned and see what we get from it.

Copy link
Member

@kwin kwin left a comment

Choose a reason for hiding this comment

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

LGTM, but would appreciate some comment in the code for the property

pom.xml Show resolved Hide resolved
Comment on lines +948 to +949
<!-- in order to restore default annotation processing behaviour, please override with empty value -->
<maven.compiler.proc>none</maven.compiler.proc>
Copy link
Member

Choose a reason for hiding this comment

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

Is there a trick to this 'override with empty value' instruction? I tried this general approach after seeing it described here, but haven't been able to get it to work. Using Maven 3.9.4 and compiler-plugin 3.13.0, when I try this I simply get: error: invalid flag: -proc:

Setting the maven.compiler.proc property in the parent disables implicit annotation processing as desired. Setting it again to empty (<maven.compiler.proc></maven.compiler.proc>) in a child pom to override that disabling does alter the property, however it then just causes an error from the compiler seemingly because it is simple being passed -proc bare which it doesnt accept, resulting in the error: invalid flag: -proc:

What am I missing?

(It works if I use "full" instead of empty for the child pom property override, but just as was discussed on this PR and the related one, I dont want to use "full" because of its reliance on recent JDK builds for the backported support of that value)

Copy link
Member

Choose a reason for hiding this comment

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

Empty values don't work unfortunately due to https://github.com/eclipse-sisu/sisu.plexus/issues/29.

Copy link
Member

Choose a reason for hiding this comment

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

I'm a little confused given it was you that had asked for the comment about empty override to be added hehe.

So it seems like the comment is really just wrong, and this approach of setting maven.compiler.proc to "none" in a parent is actually unworkable if you dont want to then have to set "full" as the property override value, and require everyone having updated JDKs < 21 with support for that value backported.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have configuration like:

<properties>
  <maven.compiler.proc>none</maven.compiler.proc>
</properties>

....

<configuration>
            <proc>${maven.compiler.proc}</proc>
</configuration>

is such case we can set empty value for property in child - it will work

such configuration in child

<configuration>
            <proc/>
</configuration>

will not work

Copy link
Member Author

Choose a reason for hiding this comment

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

please try

Copy link
Member

@gemmellr gemmellr Jun 25, 2024

Choose a reason for hiding this comment

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

That is one of a few variants I tried before asking (so is your example that wont work), and I believe is precisely what I was doing at the point when I commented earlier. I had also tried before that with just setting the property in the parent+child (i.e not explicitly configuring <proc> with its value), but had noticed you were using the value indirectly to set <proc> rather than just the property itself so I did then try that too.

I tried that version again now per your note to be sure, and it again netted only the error: invalid flag: -proc: failure.

Given it has been part of your parent pom for months, do you know if there is an actual instance of this in use somewhere in the maven project as example?

Copy link
Member Author

Choose a reason for hiding this comment

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

ups ...

% git diff
diff --git a/pom.xml b/pom.xml
index e5e60d9..2072a86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,6 +68,7 @@
     <mavenVersion>3.6.3</mavenVersion>
     <resolverVersion>1.4.1</resolverVersion>
     <project.build.outputTimestamp>2024-06-02T15:17:10Z</project.build.outputTimestamp>
+    <maven.compiler.proc />
   </properties>
mvn -V clean compile 
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)

ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project maven-help-plugin: Fatal error compiling: error: invalid flag: -proc: -> [Help 1]
mvn -V clean compile      
Apache Maven 4.0.0-beta-3 (e92f645c2749eb2a4f5a8843cf01e7441e4b559f)

[INFO] BUILD SUCCESS

by default I use Maven 4 ....
so comment is wrong 😖

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunate. Will likely just need to avoid maven.compiler.proc=none for any projects that do want to do some annotation processing, as its likely to be some time before requiring Maven 4 is viable for some of them.

I did think of an ugly alternative that seems like it may actually work: defining annotationProcessorPaths in the parent pom with a path that doesnt have any annotation processor, thus stopping it finding any unless annotationProcessorPaths is updated. Then use annotationProcessorPaths definitions with combine.children="append" (or perhaps combine.self="override" when sure there are no other potential processors...in my case there are) to add all the actual processor paths when/where needed. Stops implicit search of all the deps, and stops the warnings on JDK21/22.

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

Successfully merging this pull request may close these issues.

6 participants