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 gradle.build file under the project,
def add(String kind, String dependency) {
project.dependencies
{dep->
if(kind.equals("lib"))
{
def jar = dependency.substring(dependency.lastIndexOf("/")+1)
jar = jar.substring(0,jar.indexOf("."))
dep.compile("jarlib:$jar:0")
}
else if(kind.equals("src"))
{
def project_name = dependency.substring(dependency.indexOf("/") + 1)
dep.compile(project(":$project_name"))
}
}
}
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') >
if(!classpathFile.exists())
return
def classpath = (new XmlParser()).parse(classpathFile)
classpath.classpathentry.each{ module ->
add(project,module.@kind,module.@path)
}
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 ?