Buildship, how to 'ignore_optional_problems' in annotation (apt) generated classes

I actually solved it, this works:

build.gradle:
eclipse { classpath { file { whenMerged {
def aptSource = new org.gradle.plugins.ide.eclipse.model.SourceFolder(“.apt_generated”,“bin/main”)
aptSource.entryAttributes[‘optional’] = ‘true’
aptSource.entryAttributes[‘ignore_optional_problems’] = ‘true’
entries += aptSource
}}}}

Side note: Initially, I could configure it through Eclipse (Eclipse-> right click on Project-> Properties → Java Build Path) , but then Buildship/Gradle would remove the attribute ‘ignore_optional_problems’ from the classpath entry (or probably rewrite the whole entry with only the “optional” attribute, as the “.apt_generated” entry appeared under the buildship container). This way, “.apt_generated” is explicitly inserted and is not rewritten.
As for the error given by:
def aptSources = entries.find { it.path == ‘.apt_generated’ }
I guess Buildship writes on the classpath after whenMerged and that’s why aptSources was a null object.

1 Like