[native] Copy library to test directory before google test

I have my build and my test setup and working in gradle for my cpp project.

My tests rely on some external libraies which need to be copied to the output directory before gradle runs the tests.

copyCefTestResources is the task I need to run before the automatically generated runRoxxyTestGoogleTestExe runs.

How can I make sure that the copyCefTestResources is run before the tests when running gradle build?

I’ve tried various things, but I’m fairly out of ideas now… Is there a generic way to modify the task order in the cpp and google-test plugins?

apply plugin: 'cpp'
apply plugin: 'google-test'

def cefResourcePath = file("ceflib").absolutePath

def cefAllResources = copySpec {
    from(cefResourcePath) {
        include "*"
	include "locales/*"
    }
}

def cefTestResources = copySpec {
    from(cefResourcePath) {
        include "libcef.so"
    }
}

task copyCefResources << {
    ['build/exe/roxxy'].each { dest ->
        copy {
            with cefResources
            into dest
        }
    }
}

task copyCefTestResources << {
    ['build/exe/roxxyTest'].each { dest ->
        copy {
            with cefTestResources
            into dest
        }
    }
}

model {
    
    components {
        roxxy(NativeExecutableSpec) {
            sources {
                cpp {
                    source {
                        srcDir "src"
                        include "**/*.cc"
                        exclude "roxxyTest/*"
                    }
                }
            }
        }
    }
    
    binaries {
    	roxxyExecutable {
            if (toolChain in Gcc) {
                cppCompiler.args "-D__GXX_EXPERIMENTAL_CXX0X__", "-D__cplusplus=201103L", "-I"+cefResourcePath, "-O2", "-g3", "-Wall", "-c", "-fmessage-length=0", "-std=c++11", "-MMD", "-MP"
                linker.args "-lglog", "-ldouble-conversion", "-lpng" ,"-lpthread", "-lgflags", "-lproxygenhttpserver", "-lfolly", cefResourcePath+"/libcef.so", cefResourcePath+"/libcef_dll_wrapper.a"
            }
            cppCompiler.define "ROXXY_BUILD"
            
        }
       
    	roxxyTestGoogleTestExe {
		    if (toolChain in Gcc) {
	            cppCompiler.args "-D__GXX_EXPERIMENTAL_CXX0X__", "-D__cplusplus=201103L", "-I"+cefResourcePath, "-O2", "-g3", "-Wall", "-c", "-fmessage-length=0", "-std=c++11", "-MMD", "-MP"
	            linker.args "-lgmock", "-lgtest", "-lglog", "-ldouble-conversion", "-lpng", "-lpthread", "-lgflags", "-lproxygenhttpserver", "-lfolly", cefResourcePath+"/libcef.so", cefResourcePath+"/libcef_dll_wrapper.a"
	        }
                // HOW DO I DO THIS BIT?
	        //tasks.runRoxxyTestGoogleTestExe.dependsOn copyCefTestResources
		    //build.finalizedBy copyCefTestResources
	    }
		
	
        
    }
    
}

Have you tried using the tasks model map?

model {
    tasks {
        runRoxxyTestGoogleTestExe {
            dependsOn ...
        }
    }
}

Yeah that seems to work! Thanks.