// they want a specific version etc.
Configuration antlrConfiguration = project.getConfigurations().add(ANTLR_CONFIGURATION_NAME).setVisible(false)
.setTransitive(false).setDescription("The Antlr libraries to be used for this project.");
project.getConfigurations().getByName(COMPILE_CONFIGURATION_NAME).extendsFrom(antlrConfiguration);
final ProjectInternal projectInternal = (ProjectInternal) project;
project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().allObjects(
new Action<SourceSet>() {
public void execute(SourceSet sourceSet) {
// for each source set we will:
// 1) Add a new 'antlr' virtual directory mapping
final AntlrSourceVirtualDirectoryImpl antlrDirectoryDelegate
= new AntlrSourceVirtualDirectoryImpl(((DefaultSourceSet) sourceSet).getDisplayName(),
projectInternal.getFileResolver());
((DynamicObjectAware) sourceSet).getConvention().getPlugins().put(
AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
final String srcDir = String.format("src/%s/antlr", sourceSet.getName());
antlrDirectoryDelegate.getAntlr().srcDir(srcDir);
sourceSet.getAllSource().add(antlrDirectoryDelegate.getAntlr());