[Solved] Native build with pre-defined closure fails when building with Gradle 2.5

Hi everyone,

I have a plugin that was working fine with Gradle 2.4 and fails with 2.5. It essentially has a closure that holds all my default settings and can be called from any build script like this:

apply plugin: 'cpp' 
apply plugin: 'c'

// actually provided by a plugin
def Closure configureClosure = { 
 	baseName = project.name
	sources {				
		cpp(CppSourceSet){
		    source{ 
			srcDir "src/main"
			include "**/*.cpp"
		    }
		    exportedHeaders.srcDir "src/include"				
		}
        }
}

model {
	components {
		main(NativeExecutableSpec)  {
			configureClosure.delegate = it;
			configureClosure()
		}
	}
}

Now, with Gradle 2.5 I am getting the following error:

Cannot create 'components.main.sources.cpp' using creation rule 'model.components > main.<init> > 
components.main.getSources() > create(cpp)' as the rule 'model.components > create(main) > .sources.cpp()' 
is already registered to create this model element.

Is there a quick fix available?
Any help is appreciated!

Matthias

Try to replace:

sources {				
		cpp(CppSourceSet){
		    ...
		}
        }

with:

sources {                
        cpp {
            ...
        }
}

The first one creates a new source set, while the second one configures an existing one.

Thank you for the hint, Cédric! Good to know that it was that easy to fix it.