如何将Java代码和Junit测试与Gradle一起构建 [英] How to keep Java code and Junit tests together building with Gradle

查看:123
本文介绍了如何将Java代码和Junit测试与Gradle一起构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中主要来源和该来源的测试用例保存在相同的包/目录中.每个测试类都是要测试的类的名称,并在其末尾附加"Test".因此,如果我有一个Foo.java,它旁边将是一个FooTest.java.

I have a project in which the main source and the test cases for that source are kept in the same package/directory. Each test class is the name of the class which it is testing with "Test" appended on the end. So if I have a Foo.java there will be a FooTest.java right next to it.

我的问题是,如何使用Gradle构建该项目?我仍然希望将类文件分开,即,用于主类的文件夹和用于测试类的文件夹.

My question is, how do I build this project with Gradle? I'd still like to keep the class files separate, i.e. a folder for main classes and a folder for test classes.

推荐答案

这应该可以解决问题:

sourceSets {
    main {
        java {
            srcDirs = ["some/path"]
            exclude "**/*Test.java"
        }
    }
    test {
        java {
            srcDirs = ["some/path"]
            include "**/*Test.java"
        }
    }
}

这篇关于如何将Java代码和Junit测试与Gradle一起构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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