Build Wowza Modules Using Wowza Gradle Plugin

Posted on May 7, 2015
Share article:

Building Wowza applications with the default ant script is a bit outdated, so I wrote a post on building Wowza with Gradle. Now I’ve gone a step further and built a Wowza Gradle Plugin to help you better control your build life cycle.

Loading the Wowza Gradle Plugin

1. Create a file named wowza.plugin in the root of your project, next to your build.gradle, containing the following:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath 'ro.stancalau:wowza-gradle-plugin:2.0'
    }
}

if (!project.plugins.findPlugin(ro.stancalau.wowza.WowzaPlugin)) {
    project.apply(plugin:ro.stancalau.wowza.WowzaPlugin)
}

When editing this file, make sure you use the latest available version of the plugin in the classpath. You can check available versions here.

2. Your build.gradle file should look similar to:

apply from: 'wowza.plugin'

version = '1.0.0'
def wowzaPath = "${System.env['ProgramFiles(x86)']}/Wowza Media Systems/Wowza Streaming Engine 4.1.0"

repositories { mavenCentral() }

dependencies {
    pack([group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.1.1'],
         [group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.3.6'],
         [group: 'org.apache.httpcomponents', name: 'httpclient-cache', version: '4.3.6'],
         [group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4'])

    copylib([group: 'com.google.guava', name: 'guava', version: '18.0'])

    // Wowza 4.0 onward packages apache httpClient and there might be dependency issues:
    // http://www.wowza.com/forums/showthread.php?35743-Conflicting-classes-after-upgrade-to-4-0-1
    // Due to this fact, we exclude wms-restlet* from the wowzaLibsPath libraries as gradle tests
    // do not pass with those dependencies included.
    compile(fileTree(dir: "$wowzaPath/lib", include: '*.jar', exclude: '*wms-restlet*'))

    testCompile([group: 'junit', name: 'junit', version: '4.11'])
}

wowza {
    localWowzaPath = wowzaPath
    serviceName = 'WowzaStreamingEngine410'

    deploys {
        testAppName1 { configurationFile = file('dir1/Application.xml') }
        testAppName2 { configurationFile = file('dir2/Application.xml') }
    }
}

Just change wowzaPath to reflect your local Wowza installation folder and fiddle with the dependencies to reflect the ones your project needs. The project should then be built by running:

gradle build

The relationships between configurations are:

pack
copylib
compile.extendsFrom pack
compile.extendsFrom copylib

The dependencies from the pack configuration will end up packaged into the jar (fat jar, or jarJar). The ones from copylib will end up copied into wowzaPath /lib folder upon deploy. The java compile configuration extends from both of these so you don’t need to specify the dependencies twice for the project to compile.

Wowza Gradle Plugin Tasks

If you run the ‘gradle tasks’ command, you will notice a section named “Wowza tasks” with the specific tasks and descriptions listed. Note that the build task is from the Java Plugin and is listed under “Build tasks“. Don’t get confused, as it is also tweaked for Wowza. The build task now depends on the packageJar task and the pack dependencies will be fat-jared into the build jar.

'gradle tasks' ran on Wowza Gradle Plugin script

The relationships between tasks are as follows:

build.dependsOn packageJars
deploy.dependsOn build
restartWowza.dependsOn [stopWowza, startWowza]

To deploy some applications on your local Wowza, just run:

gradle deploy

Doing that will:

  • build the jar and copy it into wowzaPath /lib
  • deploy all the applications specified by creating appropriate directories in  wowzaPath /applications and copying the xmls into wowzaPath /conf/<appName>

After a deploy, you will be able to call ‘gradle restartWowza‘, provided your Wowza is installed as a service in your OS (should also work on Unix). If you wish to have more control on what is happening, you can call the stopWowza and startWowza tasks separately.

Ideas for Further Development of the Plugin

  • A ‘release‘ task that would create an archive containing the built jar, external dependency jars, readme file and sample Application.xml file. Maybe even deploy to Artifactory.
  • Inputs and outputs for the ‘packageJar‘ task so that it can be “UP-TO-DATE” when nothing has changed. That would speed up deployment as the build won’t trigger every time
  • Automated tests for the sample project build and deployment
  • Backup/Restore tasks for the local Wowza environment so you can roll back to the pre-deploy setup
  • Task for archiving/clearing Wowza logs

I welcome you to contribute here if you can add value to this project. I challenge you to do a pull request! 🙂

Share article:

Start the discussion on "Build Wowza Modules Using Wowza Gradle Plugin"


    What do you think? Share your thoughts!

    + 50 = 56