Gradle rootproject method call fails

(Mustafa FİDAN) #1

I am new to gradle and try to upgrade our build environment ant to gradle. i have a multiple project build configuration. What i want to do is read the .classpath file from eclipse workspace and add to gradle dependency. Below code implements this and works fine in the file under the project,

def add(String kind, String dependency) {  
                def jar = dependency.substring(dependency.lastIndexOf("/")+1)
                jar = jar.substring(0,jar.indexOf("."))
              else if(kind.equals("src"))
                def project_name = dependency.substring(dependency.indexOf("/") + 1)                

But i do not want to copy this method to every subproject and move it to root project gradle file. After this i get an error at line > dep.compile(project(":$project_name"`)) as

No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated.compile() is applicable for argum ent types: (org.gradle.api.internal.project.DefaultProject_Decorated) values: [project ‘:MYPROJECT’]

And this is the caller task

 task loadClasspath{
 	File classpathFile = new File(projectDir.getPath() + '/.classpath') > 		 	
        def classpath = (new XmlParser()).parse(classpathFile)
  	classpath.classpathentry.each{ module ->
      project.configurations.compileClasspath.each { file -> println file }

if keep both in the subproject gradle it works but if i move to root project gradle i get the above error.
Anyone can help ?