Setting "External annotations" path in eclipse projects

buildship
eclipse

(Holger) #1

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.


(Holger) #2

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.