Search code examples
groovywixgradlebuild.gradle

Using Gradle execute for wix


I have a build.gradle that compiles my project, runs test creates a jar then packages that with launch4j. I want to be able to use wix to create a installer as well, however I seem to be having a lot of trouble launching it from .execute().

The files necessary for candle and light are held in \build\installer. However trying to access those files by calling execute in the build file is always met with failure.

I have made a second build.gradle in /build/installer that does work. It is:

task buildInstaller {

def command = project.rootDir.toString() + "//" +"LSML Setup.wxs"
def candleCommand = ['candle', command]    
def candleProc = candleCommand.execute()
candleProc.waitFor()
def lightCommand = ['light' , '-ext', 'WixUIExtension', "LSML Setup.wixobj"]
def lightProc = lightCommand.execute()


}

Is there some way I can run the second build file from the main one and have it work or is there a way to call execute directly and have it work?

Thanks.


Solution

  • If your project consist of few gradle builds (gradle projects) you should use dependencies. Working with execute() method is a bad idea. I will do it in this way:

    ROOT/candle/candle.gradle

    task build(type: Exec) {
        commandLine 'cmd', '/C', 'candle.exe', '...'
    }
    

    ROOT/app/build.gradle

    task build(dependsOn: ':candle:build') {
        println 'build candle'
    }
    

    ROOT/app/settings.gradle

    include ':candle'
    project(':candle').projectDir = "$rootDir/../candle" as File
    

    BTW I had problems with Exec task so in my projects I replaced it with and.exec() so candle task may look like this:

    task candle << {
        def productWxsFile = new File(buildDir, "Product.wxs")
        ant.exec(executable:candleExe, failonerror: false, resultproperty: 'candleRc') {
            arg(value: '-out')
            arg(value: buildDir.absolutePath+"\\")
            arg(value: '-arch')
            arg(value: 'x86')
            arg(value: '-dInstallerDir='+installerDir)
            arg(value: '-ext')
            arg(value: wixHomeDir+"\\WixUtilExtension.dll")
            arg(value: productWxsFile)
            arg(value: dataWxsFile)
            arg(value: '-v')
    
        }
        if (!ant.properties['candleRc'].equals('0')) {
            throw new Exception('ant.exec failed rc: '+ant.properties['candleRc'])
        }
    }
    

    More informations about multi projects you will find here http://www.gradle.org/docs/current/userguide/multi_project_builds.html.