12

I want to run mvn clean compile in each directory in my Eclipse workspace containing a pom.xml file.

I was able to run svn update for each directory containing .svn like this:

PS C:\workspace> Get-ChildItem -recurse -force | 
where {$_.name -eq ".svn"} | 
foreach {svn update $_.parent.FullName}

However, this gives the full path to svn and runs from the current directory. The mvn clean compile needs to be run inside the directory, afaik. Tried doing the following, but then I just get an error saying something can't be null. Seems to be the first cd call it complains about. Do I just have some syntax wrong, or am I using foreach wrong?

PS C:\workspace> Get-ChildItem -recurse | 
where {$_.name -eq "pom.xml"} | 
foreach { cd $_.parent.name; mvn clean compile; cd ..; }

2 Answers 2

19

Seems like $_.parent.FullName property worked in the first case because I was filtering out only directories. In this case I filtered out files, so I got it working by using $_.DirectoryName instead.

PS C:\workspace> Get-ChildItem -recurse | 
where {$_.name -eq "pom.xml"} | 
foreach { cd $_.DirectoryName; mvn clean compile; cd ..; }
Sign up to request clarification or add additional context in comments.

2 Comments

First off, you should mark your answer as accepted. Second, how would I do this if I have lots of directories but each one of them has a directory of the svn structure branches, trunk, etc. and I want to cd into that trunk folder, and then into another folder inside called something like toplevel-trunk and then run mvn clean package?
Clean and Clear. :)
0
  • Create a batch file in the parent directory called 'foreach.bat'.

  • Edit the file in a text editor (i.e. Notepad).

  • Add this to the file:

    powershell.exe -Command "Get-ChildItem -recurse | where {$.name -eq 'pom.xml'} | foreach { cd $.DirectoryName; mvn clean compile; cd ..; }"

  • Save and close the file.

  • Run the file, eg. by double-clicking it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.