How to setup Eclipse External Null Annotations via Gradle?

I want use Eclipse External Null Annotations (EEA). I can downloade EEA definitions via

dependencies {
    compile 'org.lastnpe.eea:jdk-eea:2.1.0'
}

But Eclipse will not use it. Eclipse required to use it as an attribute property “annotationpath” in the .classpath file. Also it will be nice if the build system does not need to download it. It is only required for Eclipse. Any ides how can do this?

It looks like there’s a maven/m2e plugin here

I’m guessing you’ll have to do the same in Gradle as the M2E plugin. You can likely make use of the EclipseClasspath.withXml { ... } hook.

See EclipseClasspath

withXml does not work with refresh. The follow seams to work for me:

configurations {
  eclipseNullAnnotations
}
dependencies {
    eclipseNullAnnotations 'org.lastnpe.eea:jdk-eea:+'
}
apply plugin: 'eclipse'
eclipse {
    classpath {
        file {
            whenMerged { classpath ->
                classpath.entries.removeAll { entry ->
                    if( entry.kind == 'con' ) {
                        entry.entryAttributes.put( "annotationpath", configurations.eclipseNullAnnotations.files[0] )
                    }
                    false
                }
            }
        }
    }
}

But this work only with one annotation artifact.

Please state what you’re trying to achieve in the eclipse classpath xml (ie current state and desired state). I (and likely the other users on this list) am not aware of what changes are needed to the eclipse classpath xml to support null annotations

Details of the feature can be found at https://help.eclipse.org/2020-09/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_external_null_annotations.htm

What is needed?
The annotationpath property of an classpath container must set to a jar file or folder with the needed files. This is like the source path or java doc path.

The above hack has the problems:

  • only one file for annotationpath is possible
  • the .classpath file contains a local path which is bad with a repository

Ideally the annotationpath property will be hide in the Gradle dependency container. See the image: