使用Gradle从Cucumber/Groovy测试中创建包含依赖项的UberJar

4
我有一些功能测试在{project_home}/src/test/groovy/中。
我希望能够使用Gradle任务来:
  1. 从{project_home}/src/test/groovy/下的所有.groovy文件中制作一个包含所有依赖项的JAR文件

  2. 能够运行此JAR文件以替代单独运行Groovy文件

我找到的所有示例都有一个main方法,而我的没有main()。
因此,我尝试使用“项目”的build.gradle并附加以下内容:
task fatJar(type: Jar) {
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

我执行了$gradle clean fatJar命令,但是编译失败了:

:Tests:EndToEndFunctionalTests:fatJar FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Tests:EndToEndFunctionalTests:fatJar'.
> archive contains more than 65535 entries.

  To build this archive, please enable the zip64 extension.
  See: https://docs.gradle.org/2.7/dsl/org.gradle.api.tasks.bundling.Zip.html#org.gradle.api.tasks.bundling.Zip:zip64

我在 /build/libs 目录下有一个 jar 文件。

1个回答

6
task uberJar(type: Jar,dependsOn:[':compileGroovy']) {
    zip64 true
    from files(sourceSets.main.output.classesDir)
    from configurations.runtime.asFileTree.files.collect {zipTree(it) }
    with jar

}

解决了问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接