配置Gradle以将主要类和测试类包含到我的.jar存档中 [英] Configure Gradle to include main classes as well as test classes into my .jar archive

查看:106
本文介绍了配置Gradle以将主要类和测试类包含到我的.jar存档中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何配置Gradle在我的.jar存档中包含主类和测试类。目前,在 build / libs 目录中构建的.jar缺少我的测试类。在Gradle将它们编译为 project-root / bin / com / package / <后,它仅包含.jar中来自 project-root / src / main / java / com / package 的类。 / strong>。

How do I configure Gradle to include main classes as well as test classes into my .jar archive. Currently the .jar that gets built in the build/libs directory is missing my test classes. It is only including classes sourced from project-root/src/main/java/com/package in the .jar after Gradle compiles them into project-root/bin/com/package/ .

jar {
    manifest {
        attributes 'Implementation-Title': title, 'Implementation-Version': version, 'Main-Class': mainTestClass
    }
}

更奇怪的是,虽然Gradle将已编译的测试类与主类一起放入 project-root / bin / com / package / ,但奇怪的是,它决定不将其放入.jar存档。那么,如何使.jar也包含最初来自 project-root / src / test / java / com / package / 目录的测试类?

The wierd thing is that while Gradle is putting the compiled test classes into project-root/bin/com/package/ ALONG with the main classes, it strangely is deciding to not put them into the .jar archive. So, how do I get the .jar to also include the test classes that were originally sourced in the project-root/src/test/java/com/package/ directory?

这是我的build.gradle文件,我需要帮助。

推荐答案

来自文档


Java插件定义了两个标准的源集,分别称为main和test 。主要源代码集包含您的生产源代码,该源代码被编译并组装为一个JAR文件。测试源集包含使用JUnit或TestNG编译和执行的单元测试源代码。

The Java plugin defines two standard source sets, called main and test. The main source set contains your production source code, which is compiled and assembled into a JAR file. The test source set contains your unit test source code, which is compiled and executed using JUnit or TestNG.

高度怀疑您会想要在罐子中进行测试,但将它们添加到主要源集中可能是最简单的解决方案。

It's highly suspect that you would want your tests in your jar, but adding them to the main source set would likely be the simplest solution.

这篇关于配置Gradle以将主要类和测试类包含到我的.jar存档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆