我刚接触gradle当前我在编译测试类时遇到了问题我在测试类中引用Java类来测试程序,但我无法编译。问题我不了解如何将Java src结构与测试结构链接或引用。有人可以帮我解决问题。
下面我提供了Src和测试包结构和编译问题的截图。
Java Src和测试结构
编译错误
build.properties
apply plugin: 'java'
sourceCompatibility = '1.7'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
// NetBeans will automatically add "run" and "debug" tasks relying on the
// "mainClass" property. You may however define the property prior executing
// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
//
// Note however, that you may define your own "run" and "debug" task if you
// prefer. In this case NetBeans will not add these tasks but you may rely on
// your own implementation.
if (!hasProperty('mainClass')) {
ext.mainClass = ''
}
jar {
manifest {
attributes 'Main-Class': 'com.gradle.shopcart.ShopCartApp'
}
}
repositories {
mavenCentral()
// You may define additional repositories, or even remove "mavenCentral()".
// Read more about repositories here:
// http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories
}
dependencies {
// TODO: Add dependencies here ...
// You can read more about how to add dependency here:
// http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
testCompile group: 'junit', name: 'junit', version: '4.12'
}
修改::
我使用netbeans,在gradle插件的帮助下,我在下面创建了这个项目结构,你可以找到截图。如果我错过了什么,请纠正我。
如有更多信息,请通知我。