Our c++ build process is using a different scheme for the objects/libs/exe produced compare to the one used by gradle. Specifficaly
The debug version has the same same as the release version with a ‘d’ appended, ie. food.exe is the debug version while foo.exe is the release version as well as bard.dll is the debug version while bar.dll is the release version
All exe (debug and release) are going into the project/bin directory
All lib (debug & release) are going into the project/lib directory
All dll (debug & release) are going into the project/bin directory
Is there a easy way to change gradle to produce such artifacts?
It might be easier to create a copy task that collects all resulting binaries. To dynamically detect which binaries need to be copied, I would write a plugin, like so (I haven’t tested it):
I am trying your proposal but I got this error
A problem occurred configuring root project ‘Foundation’.
There is a problem with model rule BinaryCollectorPlugin#createCollectBinariesTask(ModelMap, ModelMap).
Type-only model reference of type org.gradle.model.ModelMap<org.gradle.nativeplatform.NativeBinarySpec> (parameter 2) is ambiguous as multiple model elements are available for this type:
- binaries (created by: BinaryBasePlugin.Rules#binaries(BinaryContainer))
- components (created by: ComponentBasePlugin.PluginRules#components(ComponentSpecContainer))
To fix that issue, we have to tell Gradle how to resolve the ambiguity. The easiest way is to annotate the parameter with the model path of the desired element. In our case, we want the binaries. The method declaration becomes:
Thanks for the fix on the ambiguity… Now I got this error
gradle --no-daemon collectBinaries --stacktrace
Caused by: org.gradle.api.InvalidUserDataException: No value has been
specified for property ‘destinationDir’.
at
org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:47)
A problem was found with the configuration of task ‘:collectBinaries’.
That’s weird. It seems that no binaries were added. Could you please add a debug line in the addBinary method so that we can see if it’s finding the binaries properly?
task.from(BinaryFile) {
System.err.println("Adding binary $binaryFile to $destinationDirectory");
...
And also debug line before the if conditions in the collectBinaries method:
String buildType = binary.buildType.name
System.err.println("Found binary $binary of type ${binary.class}")
System.err.println("Build type is: $buildType")
...
This way, we can see if the destination directory wasn’t set because it didn’t add any binaries.