How to run JBoss TattleTale from inside Gradle build

892 views Asked by At

I am in love with JBoss TattleTale. Typically, in my Ant builds, I follow the docs to define the Tattletale tasks and then run them like so:

<taskdef name="report"
    classname="org.jboss.tattletale.ant.ReportTask"
    classpathref="tattletale.lib.path.id"/>

...

<tattletale:report source="${src.dir]" destination="${dest.dir}"/>

I am now converting my builds over to Gradle and am struggling to figure out how to get Tattletale running in Gradle. There doesn't appear to be a Gradle-Tattletale plugin, and I'm not experienced enough with Gradle to contribute one. But I also know that Gradle can run any Ant plugin and can also executing stuff from the system shell; I'm just not sure how to do this in Gradle because there aren't any docs on this (yet).

So I ask: How do I run the Tattletale ReportTask from inside a Gradle build?


Update

Here is what the Gradle/Ant docs show as an example:

task loadfile << {
    def files = file('../antLoadfileResources').listFiles().sort()
    files.each { File file ->
        if (file.isFile()) {
            ant.loadfile(srcFile: file, property: file.name)
            println " *** $file.name ***"
            println "${ant.properties[file.name]}"
        }
    }
}

However, no where in here do I see how/where to customize this for Tattletale and its ReportTask.

2

There are 2 answers

0
sagneta On

The previous answers either are incomplete or excessively complicated. What I did was use the ant task from gradle which works fine. Let's assume your tattletale jars are beneath rootDir/tools/...

ant.taskdef(name: "tattleTaleTask", classname: "org.jboss.tattletale.ant.ReportTask", classpath: "${rootDir}/tools/tattletale-1.1.2.Final/tattletale-ant.jar:${rootDir}/tools/tattletale-1.1.2.Final/tattletale.jar:${rootDir}/tools/tattletale-1.1.2.Final/javassist.jar")
sources = "./src:./src2:./etcetera"
ant.tattleTaleTask(
    source: sources,
    destination: "tattleTaleReport",
    classloader: "org.jboss.tattletale.reporting.classloader.NoopClassLoaderStructure",
    profiles: "java5, java6",
    reports: "*",
    excludes: "notthisjar.jar,notthisjareither.jar,etcetera.jar"
    ){

    }

So the above code will generate the report beneath ./tattleTaleReport. It's that simple. The annoyance is that the source variable only accepts directories so if there are jars present in those directories you do not wish to scan you need to add them to the excludes parameter.

0
Mark Pollard On

The following is adapted from https://github.com/roguePanda/tycho-gen/blob/master/build.gradle

It bypasses ant and directly invokes the Tattletale Java class.

It was changed to process a WAR, and mandates a newer javassist in order to handle Java 8 features such as lambdas.

configurations {
    tattletale
}

configurations.tattletale {
    resolutionStrategy {
        force 'org.javassist:javassist:3.20.0-GA'
    }
}

dependencies {
    // other dependencies here...
    tattletale "org.jboss.tattletale:tattletale:1.2.0.Beta2"
}

task createTattletaleProperties {
    ext.props = [reports:"*", enableDot:"true"]
    ext.destFile = new File(buildDir, "tattletale.properties")
    inputs.properties props
    outputs.file destFile
    doLast {
        def properties = new Properties()
        properties.putAll(props)
        destFile.withOutputStream { os ->
            properties.store(os, null)
        }
    }
}

task tattletale(type: JavaExec, dependsOn: [createTattletaleProperties, war]) {
    ext.outputDir = new File(buildDir, "reports/tattletale")
    outputs.dir outputDir
    inputs.files configurations.runtime.files
    inputs.file war.archivePath
    doFirst {
        outputDir.mkdirs()
    }
    main = "org.jboss.tattletale.Main"
    classpath = configurations.tattletale
    systemProperties "jboss-tattletale.properties": createTattletaleProperties.destFile
    args([configurations.runtime.files, war.archivePath].flatten().join("#"))
    args outputDir
}