Open solarmosaic-kflorence opened 3 years ago
As a side note, when running tests in a sub-project the files are already written to the correct place (sub-project target/pacts
by default).
EDIT: actually, when I run the tests inside of intelliJ they seem to write to the root project target/pacts
folder, but when I run them from the command line they write to the project target/pacts
folder...
I guess I'm less concerned about the default path, as long as it is consistent for both tests and SBT tasks. To clarify I am currently seeing the following behavior:
sbt test
is run from command line, pact files are output to the sub-project/target/pacts
directorytarget/pacts
directorysbt pactPack
are run, they are currently always looking in the root project target/pacts
directorySo it seems like the current oddball is the output location of sub-project tests. Strangely, when I debug the code, file.getAbsolutePath
points to the root project target/pacts
directory, but when file.createNewFile()
is called, it creates the file in sub-project/target/pacts
... must have something to do with the workspace Java is using.
Oddly enough, this works:
val file1 = new File("target/pacts")
println(file1.getAbsolutePath)
val file2 = new File(file1.getAbsolutePath + "/" + UUID.randomUUID())
file2.createNewFile()
println(file2.getAbsolutePath)
To use an absolute path instead of a relative path will fix the issue.
For now I can use this workaround with ScalaPactForgerDsl
:
implicit override val options: ScalaPactOptions = ScalaPactOptions(
writePactFiles = true,
outputPath = new File("target/pacts").getAbsolutePath
)
Will open a PR for this tomorrow.
Currently
ScalaPactEnv
setsoutputPath
toNone
by default:In various places, a default value of
"target/pacts"
is then assigned. For example: https://github.com/ITV/scala-pact/blob/7e1ef1244ad584e906b115330d5514000cf7f812/scalapact-shared/src/main/scala/com/itv/scalapact/shared/ScalaPactSettings.scala#L25This results in the project root
target/pacts
folder being used by default, even for sub-projects. This means by default, pact commands will fail on sub-projects. I would suggest instead, we use a default of(target.value / "pacts").getPath
as provided by SBT, for example:This way the default target path will work on sub-projects by default. This means we should probably also update the logic so that other places in the code will expect the
outputPath
to always be defined and used as a fallback toProperties.envOrElse("pact.rootDir")
so that defining the system override will still take precedence.