如何为TestNG Kotlin项目添加gradle支持?
我目前有一个testot安装Kotlin项目,当我右键单击src/test/kotlin
文件夹,并选择Run All Tests
。 有用。
但是当我尝试用gradle
输出一个源代码jar(包含测试用例)时,它开始抱怨:
18:38:08: Executing task 'sourcesJar'... e: /Users/a/codes/objjson/src/test/kotlin/tests.kt: (7, 12): Unresolved reference: testng
e: /Users/a/codes/objjson/src/test/kotlin/tests.kt: (22, 5): Unresolved reference: assertEquals
e: /Users/a/codes/objjson/src/test/kotlin/tests.kt: (60, 6): Unresolved reference: Test
....... :compileKotlin FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileKotlin'. > Compilation error. See log for more details * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED in 5s 1 actionable task: 1 executed Compilation error. See log for more details 18:38:14: Task execution finished 'sourcesJar'.
我只是尝试在测试文件中导入包:
import org.testng.Assert import org.testng.annotations.Test import org.testng.AssertJUnit.assertEquals import kotlin.reflect.KClass
我已经在设置中添加了testng
。 我的build.gradle
是:
plugins { id "org.jetbrains.kotlin.jvm" version "1.2.10" } repositories { mavenCentral() } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib" compile "org.jetbrains.kotlin:kotlin-reflect" testCompile "org.jetbrains.kotlin:kotlin-test" testCompile 'org.testng:testng:6.13.1' } sourceSets { main.kotlin.srcDirs += 'src/' } task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' from sourceSets.main.allSource } artifacts { archives sourcesJar }
我在这里错过了什么?
我使用最新版本的IDEA
。
- Android:仪器运行失败,由于“java.lang.ClassNotFoundException”:未找到测试
- 在build.gradle文件中的compileKotlin块会抛出错误“Could not find method compileKotlin()for arguments ”
- Kotlin在Android Studio 3.0 Canary 2中使用Android DataBinding
- Gradle花时间看似无所事事
- Kotlin脚本为Gradle配置 – 传递参数不使用扩展名
- Gradle无法在Windows上读取正确的本地Maven存储库
- 在一个Android项目中,Jacoco报告了Kotlin类的unit testing覆盖率
- Gradle错误升级到Android Studio 3.0 Beta 1
- 为什么intelliJ IDEA依赖范围是“提供”而不是“编译”?