Setting "External annotations" path in eclipse projects

Since release 4.5 Eclipse supports an “External annotation” path attribute on the build path’s library containers or individual jars (https://help.eclipse.org).

Is there already a way to set this “External annotation” path attribute via the eclipse plugin in build.gradle (e.g. like it is possible for the “Access rule” attributes)?

I have checked the eclipse model API but did not find anything.

Ok, found a solution. The following block does the trick:

eclipse {
	classpath {
		downloadSources = true
		downloadJavadoc = true
		file {
			whenMerged {
				def eeaPath = project.findProperty("eclipse.eeaPath");
				 
				entries.forEach {
					if(it.path.startsWith("org.eclipse.jdt.launching.JRE_CONTAINER")) {
						if(eeaPath != null) {
							it.entryAttributes.put("annotationpath", eeaPath)
						}
					} else if(it.path.contains("/caches/modules-2/")) {
						if(eeaPath != null) {
							it.entryAttributes.put("annotationpath", eeaPath)
						}
					}
				}
			}
		}
	}
}

Note that eclipse.eeaPath is an optional project property defining the actual location of eea file tree. If this property is not present no eea path is added.

1 Like

This modify the .classpath file for every user individually.

Also seems the property to accept only one value (jar or folder). Or is it possible to more as one path?