You can create a file tree - http://www.gradle.org/docs/current/userguide/working_with_files.html - with include filter matching **/SpecFlow.exe
and then call its http://www.gradle.org/docs/current/javadoc/org/gradle/api/file/FileCollection.html#getSingleFile() and obtain path from it. Of course there is a question how you want to handle case when there are more versions of this package installed.
Is there a way to use wildcards for a windows directory path in a Gradle script?
-
09-07-2023 - |
Question
I have a Gradle script that needs to look in a file path for SpecFlow.exe. The problem is, the path will include the current version of SpecFlow in the name. Since I will be using similar scripts within many projects using SpecFlow, I don't want them to have to be coupled to a specific version in case we upgrade in the future. This is what the task/command looks like currently:
task testReports (type: Exec) {
mkdir('testReports')
commandLine 'cmd', '/c', '..\\packages\\SpecFlow.1.9.0\\tools\\specflow.exe','nunitexecutionreport', 'pathtocsproj/myproject.csproj', '/xmlTestResult:..\\nunitoutput_myproject.xml', '/out:testReports\\TestResult_myproject.html'
}
I tried the following:
task testReports (type: Exec) {
mkdir('testReports')
commandLine 'cmd', '/c', '..\\packages\\SpecFlow.*\\tools\\specflow.exe', 'nunitexecutionreport', 'pathtocsproj/myproject.csproj', '/xmlTestResult:..\\nunitoutput_myproject.xml', '/out:testReports\\TestResult_myproject.html'
}
But that gave me an error: "> Process 'command 'cmd'' finished with non-zero exit value 1"
Is there a way for me to include wildcards in this path?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow