Gradle issue which trying to run dependent projects by reading a file having projets list


(Vinay Verma) #1

I am facing a strange issue in gradle. I created a deploy.gradle script which reads a file and check if my current project depends on any other project and deploys then.
I made entries in that file something like this:

(**Dependency.List** File Content):
    SyncProj-->depends-->DataSync1
    SyncProj-->depends-->DataSync2

In this case, my deploy.gradle script reads the file and splits line (split by ‘–>depends–>’) and picks up the second project and run it (by calling the same script).

//I am passing projName as commandline argument here while running the script.

Script Content:

task deployProject {
	/*Code to run the deploy project on the basis of provided 'projName' (here it is 'SyncProj') */
}

	/*Then I run following code to check if any other dependent project is mentioned in Dependecy.list file and run that project afterwards.*/
	
buffer = new BufferedReader(new FileReader("$MyFilePath/Dependency.List"));
String DependencyBuffer = ""
while ((DependencyBuffer = buffer.readLine()) != null)
{
	String[] content = DependencyBuffer.split("-->depends-->")
	if(projName.equals(content[0])) 
	{
		dependentProject = content[1];
		println "\n> Dependent Project to be Deployed: '$dependentProject'"
		
		def deployDependents = tasks.create(name: "deploy_$dependentProject", type: GradleBuild)
		deployDependents.tasks = ['deployProject']
		deployDependents.buildFile = "D:/myworkspace/filePath/deploy.gradle"
		deployDependents.startParameter.projectProperties = [projName: "$dependentProject"]
		try {
			deployDependents.execute()
		} catch (e){
					println "Deployment Error"
					println e.printStackTrace()
		}
	}
}

The code is running perfectly fine for the file structure (Dependecy.List) like below. and runs all the depedent projects If I pass projName=SyncProj.

(Dependency.List File Content):
    SyncProj-->depends-->DataSync1
    SyncProj-->depends-->DataSync2

but for the file content(Dependency.List) like:

(Dependency.List File Content):
    SyncProj-->depends-->DataSync1
    SyncProj-->depends-->DataSync2
    DataSync1-->depends-->RemoteSync1
    DataSync1-->depends-->RemoteSync2

There are two cases I have seen:

1> (When I pass projName = SyncProj in cmd line args)

Ideally What it should do: It Should go and run ‘deployProject’ for “SyncProj” > then “DataSync1” > then finally “RemoteSync1” and “RemoteSync2” and “DataSync2”.

What it is Doing: It is Running only “SyncProj”, “DataSync1” and “DataSync2”. And not Running “RemoteSync1” and “RemoteSync2”.

2> (When I pass projName = DataSync1)

What it is Doing: It is Running RemoteSync1 and RemoteSync2 projects (As expected).

Can somebody guide me what is wrong with the (1>) first case Or say What wrong I am doing here.
I need to pass ‘projName=SyncProj’ only and it should run all the dependents.

Thanks in Advance.


(Vinay Verma) #2

For this problem, if(projName.equals(content[0])) was returning false for First case.
I converted projName to String using java’s toSting() method and it worked for me :slight_smile: