4

我爱上了JBoss TattleTale。通常,在我的 Ant 构建中,我按照文档定义 Tattletale 任务,然后像这样运行它们:

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

...

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

我现在正在将我的构建转换为 Gradle,并且正在努力弄清楚如何让 Tattletale 在 Gradle 中运行。似乎没有 Gradle-Tattletale 插件,而且我对 Gradle 的经验不足,无法贡献一个。但我也知道 Gradle 可以运行任何 Ant 插件,也可以从系统 shell 执行东西;我只是不确定如何在 Gradle 中执行此操作,因为(还)没有任何文档。

所以我问:如何ReportTask从 Gradle 构建中运行 Tattletale?


更新

以下是 Gradle/Ant 文档作为示例显示的内容:

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]}"
        }
    }
}

但是,我在这里看不到如何/在哪里为 Tattletale 及其ReportTask.

4

2 回答 2

1

以下内容改编自https://github.com/roguePanda/tycho-gen/blob/master/build.gradle

它绕过 ant 并直接调用 Tattletale Java 类。

它被更改为处理 WAR,并要求使用更新的 javassist 来处理 Java 8 功能,例如 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
}
于 2016-10-27T16:07:24.210 回答
0

以前的答案要么不完整,要么过于复杂。我所做的是使用 gradle 中的 ant 任务,它工作正常。让我们假设你的 tattletale 罐子在 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"
    ){

    }

所以上面的代码会在./tattleTaleReport 下生成报告。就是这么简单。令人烦恼的是变量只接受目录,因此如果这些目录中存在您不想扫描的 jar,则需要将它们添加到excludes参数中。

于 2017-10-02T14:46:05.450 回答